公告:

wordpress特色图像功能的开启和使用介绍

作者:star0312 / 时间:12年前 (2013/06/24) / 分类:未命名 / 阅读:2102 / 评论:0

自从2.9版本以来,wordpress引入了特色图像功能,如果你的wordpress主题支持该功能,那么使用特色图像将可以很方便地在首页、分类页等列表页面显示指定的文章缩略图。

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

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

123
if ( function_exists( 'add_theme_support' ) ) {	add_theme_support( 'post-thumbnails' );}

2、发布文章时,在右侧边栏处设置特色图像

wordpress特色图像功能的开启和使用介绍

也可以在上传图片后设置。

wordpress特色图像功能的开启和使用介绍

3、在需要显示特色图像的地方插入以下代码:

12345
<?php if ( has_post_thumbnail()) : ?>   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >   <?php the_post_thumbnail(); ?>   </a> <?php endif; ?>

特色图像缩略图尺寸参数设置:

12345
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) );  // 自定义

其中 thumbnail、medium、large的默认尺寸在后台-设置-媒体中定义。





  • 我的QQ二维码
  • QQ群
  • 我的微信二维码
  • 微信公众号

没有评论,留下你的印记,证明你来过。


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。