简体   繁体   English

如何从 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);

i am using above coding in my site for getting rss feed from http://runap.app.com/feed .我在我的网站中使用上述编码从http://runap.app.com/feed获取 rss 提要。 for the above i am getting only recent posts title,description and categories.i can't get the post's images?...how can i get those images?..对于以上内容,我只获得最近的帖子标题、描述和类别。我无法获得帖子的图片?...我怎样才能获得这些图片?..

Add following code at the bottom of your child theme's functions.php file.在子主题的 functions.php 文件的底部添加以下代码。 It is recommended to customize this using a child theme.建议使用子主题对其进行自定义。

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

Once you did that blog post images will be available in your RSS feed.完成后,您的 RSS 提要中将提供该博客文章图像。

Since the images do not seem to be in the RSS feed, you should do it in two steps:由于图像似乎不在 RSS 提要中,因此您应该分两步进行:

  1. Load the RSS feed and extract all page links from it加载 RSS 提要并从中提取所有页面链接
  2. Fetch each page link and extract the image URLs from there获取每个页面链接并从那里提取图像 URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM