照片RSS源显示
我有一个WordPress博客http://cgvector.com,我想在RSS Feed中显示精选图像。我怎样才能做到这一点?我的饲料地址是:http://feeds.feedburner.com/cgvector照片RSS源显示
我已添加此代码,但它不起作用。
function featuredtoRSS($content) {
global $post;
if (has_post_thumbnail($post->ID)){
$content = '' . get_the_post_thumbnail($post->ID, 'thumbnail', array('style' => 'float:left; margin:0 15px 15px 0;')) . '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
function custom_feed($content) {
return wp_get_attachment_image(get_post_thumbnail_id(), 'full') . '<br />' . $content;
}
add_filter('the_content_feed', 'custom_feed');
这应该为你做的伎俩......
您的代码看起来不错,但你可以在你的functions.php
位于内侧粘贴此代码(所有最相同的,反正)您wp-content/themes/yourtheamefolder
function img_to_rss($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>'.get_the_post_thumbnail($post->ID).'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'img_to_rss');
add_filter('the_content_feed', 'img_to_rss');
上记住,Feedburner
缓存您的饲料,所以等待12-24个小时来更新您看到这些变化之前。
它无法正常工作,我已经添加完整的代码在jsfiddle请检查 http://jsfiddle.net/rizwanabbasi/ZXPXB/ –
我想或者你可以尝试这些插件之一[WP RSS Images](http://wordpress.org/extend/plugins/wp-rss-images/screenshots/)和[插入RSS缩略图](http://wordpress.org/extend/plugins/wp-insert-rss-缩略图/),希望这有助于。 –
wp Rss图片我以前用过这个不好,但其他我要检查希望这将工作感谢您的回复 –
我应该把这段代码粘贴到函数文件中...... –
yes在functions.php – tinyhook
我应该在哪里将这段代码粘贴到函数文件中,在php代码中或者没有php代码的末尾开始。 –