WordPress Get RSS Feed with Thumbnail Images


I was recently approached by one of my friend who needed a small help in WordPress. He own two blogs and he wanted to display the feeds of the second blog in the first blog. That was quite easy as there are many plugins, inbuilt within WordPress that can do the job. But he wanted to display the thumbnail images too along with the title.

After a long search I got few plugins, but none of them seemed to work. So finally gave up searching and starting to do something myself. I them figured out a solution to this and could successfully bring the image as well as the post title, as in the below shown image.

iab11 Wordpress Get RSS Feed with Thumbnail Images

Feed with Images from External Website

How to Get RSS Feeds with Images from other Site

Below listed is a small code that I have used to grab the RSS Feeds with Images from another website in WordPress. The name of the thumbnail image and the post name must match for the image to be grabbed. There are ofcourse methods to get the first image of the post, but I stronger suggest using Custom Field.

<?php
include_once(ABSPATH.WPINC.’/rss.php’); // path to include script
$feed = fetch_rss(‘http://indianmotosblog.com/feed/’); // specify feed url
$items = array_slice($feed->items, 0, 5); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>
<h4><img id=”rkdperil” src=” <?php
$pubdate = substr($item['pubdate'], 0, 16);
$a=”http://indianmotosblog.com/wp-content/uploads/”;
$a.=substr($pubdate,12,4);
$a.=”/”;
$m=substr($pubdate,8,3);
if($m == “Jan”){$a.=”01″;}
elseif($m == “Feb”){$a.=”02″;}
elseif($m == “Mar”){$a.=”03″;}
elseif($m == “Apr”){$a.=”04″;}
elseif($m == “May”){$a.=”05″;}
elseif($m == “Jun”){$a.=”06″;}
elseif($m == “Jul”){$a.=”07″;}
elseif($m == “Aug”){$a.=”08″;}
elseif($m == “Sep”){$a.=”09″;}
elseif($m == “Oct”){$a.=”10″;}
elseif($m == “Nov”){$a.=”11″;}
else{$a.=”12″;}
$a.=”/”;
echo $a;
$str= $item['link'];
$len=strlen($str);
$test=substr($str,27,($len-1));
echo $test;
?>.jpg” width=”90″ height=”60″ alt=<?php echo $item['title']; ?> style=”border: none;align:left;”/><div style=”clear:both”></div><a href=”<?php echo $item['link']; ?>”><?php echo $item['title']; ?></a></h4>
<?php endforeach; ?>
<?php endif; ?>

5 Responses

  1. Fabio says:

    Hi, i’m trying to use this code, but its returning a “/” before “.jpg”.

    ex:

    …/fracasso-pitty/.jpg

    The result that i need is:

    …/fracasso-pitty.jpg

    What have I to change on code to work?

    thank you,

    Fabio

    • Ramkumar says:

      Hi do you see $len-1, replace that with $len-2 ., I guess that must work , if not kindly write down the code that you wrote , I will edit it for you. Cheers

    • Fabio says:

      Replaced and nothing has changed. I’m trying to implement the code on this website (http://www.autobuzz.com.br/)

      Here’s the code:

      items, 0, 5); // specify first and last item
      ?>

      <img id="rkdperil" src=" .jpg” width=”90″ height=”60″ alt= style=”border: none;align:left;”/><a href="”>

  2. Fabio says:

    You can see the code here: http://www.autobuzz.com.br/code/

    thank you

  3. Titmumu says:

    Hello,

    I want to do exactly the same thing, put this feed http://www.tripteaser.fr/feed/reportage into my blog sidebar to have my latest reports display on. Is it possible to do that with your code even if my website images are not in the same folder ? Which url should i put line 10 ?

    Thank you in advance for your help.

Leave a Reply

© 2010 ByteChip – The Complete Technology Blog. All rights reserved.