1

我试图在functions.php中使用这个函数获取帖子的缩略图并将它们添加到我的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,论文主题。

谢谢!

4

1 回答 1

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

于 2011-05-04T01:53:06.033 回答