wordpress特色图像功能轻松添加缩略图
wordpress自2.9版本开始引入了特色图片功能,此功能可以让你轻松地在首页、分类页或其它页面显示文章的缩略图。
如果你使用的wordrpress主题没有特色图片功能,可以通过以下方法设置。
1、在主题文件夹下的functions.php文件中加入代码:
1 2 3 |
if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); } |
2、此时进入文章编辑页右侧将会见到一个新增的特色图像栏。
3、点击"添加特色图像",设置特色图像保存后:
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
Related Posts
- 修改wordpress评论默认头像的方法 (1.000)
- wordpress文章编辑器增强技巧 (1.000)
- 给wordpress博客的特定关键词自动加粗 (1.000)
- WordPress 添加面包屑导航的三种方法 (1.000)
- CSS实现WordPress文章每段首行缩进两个字符 (1.000)