如何在Wordpress中从RSS feed获取图像?

问题描述

|
       $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);
我在我的网站上使用上述代码从http://runap.app.com/Feed获取RSS Feed。对于上述我只获得最近的帖子标题,描述和类别。我无法获取帖子的图片?...我如何获取那些图片?     

解决方法

        由于图像似乎不在RSS feed中,因此您应该分两个步骤进行操作: 加载RSS feed并从中提取所有页面链接 获取每个页面链接并从那里提取图像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 feed中将提供博客文章图像。