海阔凭鱼跃,天高任鸟飞!

天高任鸟飞

       

如何在RSS中显示 Thumbnail 缩略图

作者:     目录: PHP+MySQL     发表: 2010年11月25日

自3.O开始,Wordpress 开始增加 thumbnail 缩略图功能,现在很多 WordPress 主题都支持 thumbnail 功能,那么如何让thumbnail 显示在 RSS 中呢?

要想使用Thumbnail缩略图功能,你的博客主题必须支持 Thumbnail 才可以,只需要在主题文件夹下的 functions.php 文件中增加下面的代码即可。

// This theme uses post thumbnails
	add_theme_support( 'post-thumbnails' );

要想在博客中显示缩略图,只需要在相应的位置增加如下代码:

<?php echo the_post_thumbnail();?>

从原理上讲,Thumbnail 缩略图是 WordPress 预设的 一个 自定义栏目,不属于文章内容(<?php the_content(”); ?>)的一部分,因此,默认情况下RSS是不会显示 Thumbnail 缩略图的。

在RSS中增加 Thumbnail 缩略图,只需要在functions.php中增加如下代码即可:

// show post thumbnails in feeds
function diw_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');

增加上述代码之后,就可以在RSS中看到,每篇文章的末尾都有缩略图。

2 个评论

  1. 优趣说道:

    楼上说的对哦!一般很少用

  2. zwwooooo说道:

    缩略图通常用来“装饰”主题+索引,rss一般不太需要,不过这个方法可以用来输出一些版权说明等。

发表评论