如何在wordpress中从RSS源获取图像


How can i get images from RSS feed in wordpress?

       $ch = curl_init("http://runap.app.com/feed");
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_HEADER, 0);
       $data = curl_exec($ch);
       curl_close($ch);
       $doc = new SimpleXmlElement($data, LIBXML_NOCDATA);

我在我的网站上使用上面的代码来获取rss提要http://runap.app.com/feed.对于以上内容,我只得到最近的帖子标题、描述和类别。我无法获得帖子的图片?。。。我怎样才能得到这些图像?。。

由于图像似乎不在RSS提要中,因此应该分两步完成:

  1. 加载RSS源并从中提取所有页面链接
  2. 获取每个页面链接并从中提取图像URL

在子主题的functions.php文件底部添加以下代码。建议使用子主题对此进行自定义。

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');

一旦你做到了,博客文章的图片将在你的RSS源中可用。