2011-05-04 71 views
1

我想在functions.php中使用此函数来获取帖子的缩略图并将它们添加到我的RSS提要。WordPress的add_filter()将第一张图片添加到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'); 

问题是 - 这使我的服务器崩溃。我得到一个500错误。如果我将add-filter行注释掉,则不会出现错误。

任何人都会举手这是怎么回事?我正在使用Wordpress 3.1.2,论文主题。

谢谢!

回答

1

我已经在我的开发站点上测试过你的代码,它按预期工作。由于未启用后期缩略图支持,因此可能无法使用。食典:

To enable Post Thumbnails, the current theme must include add_theme_support('post-thumbnails'); in its functions.php file. 

来源:

http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

+0

这很有趣,感谢您的评论 - 我会考虑这一点,并更新找回 – pepe 2011-05-04 02:04:10