开发者

How can i get images from RSS feed in wordpress?

       $ch = curl_in开发者_如何学Goit("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. 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?..


Since the images do not seem to be in the RSS feed, you should do it in two steps:

  1. Load the RSS feed and extract all page links from it
  2. Fetch each page link and extract the image URLs from there


Add following code at the bottom of your child theme’s functions.php file. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜