wordpress特色图像功能轻松添加缩略图

2014年05月27日 WordPress 没人吐槽 4185次浏览
博客主机

wordpress自2.9版本开始引入了特色图片功能,此功能可以让你轻松地在首页、分类页或其它页面显示文章的缩略图。

如果你使用的wordrpress主题没有特色图片功能,可以通过以下方法设置。

1、在主题文件夹下的functions.php文件中加入代码:

1
2
3
if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
}

2、此时进入文章编辑页右侧将会见到一个新增的特色图像栏。

wordpress特色图像功能轻松添加缩略图 wp技巧

3、点击"添加特色图像",设置特色图像保存后:

wordpress特色图像功能轻松添加缩略图 wp技巧

4、在需要显示缩略图的相应文件插入如下代码,即可显示该文章的缩略图:

1
2
3
4
5
 <?php if ( has_post_thumbnail()) : ?>
   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail(); ?>
   </a>
 <?php endif; ?>

缩略图尺寸参数设置:

1
2
3
4
5
6
the_post_thumbnail('thumbnail');       // 小缩略图 (默认 150px x 150px )
the_post_thumbnail('medium');          // 中缩略图 (默认 300px x 300px )-自适应图像比例
the_post_thumbnail('large');           // 大缩略图 (默认 640px x 640px )-自适应图像比例
the_post_thumbnail('full');            // 完整尺寸 
 
the_post_thumbnail( array(100,100) );  // 自定义
转载自网络:http://www.web589.com/posts/1733.html
博客主机

给我留言