Top Menu

How to Display Thumbnail from WordPress RSS feed using SimplePie?

I was designing home page for my theme showcase WordPress site Themeappears which is MultiSite enabled. The requirement was to display the recent post thumbnail from sub domains(Premium WordPress, Free WordPress and Free Blogger) in home page.

I decided to use SimplePie to syndicate my feeds. I searched the web and found Flickr Gallery with SimplePie but it was for flickr feed. I needed one which can read WordPress RSS feed and display the image from the post as thumbnail. So i decided to build with this sample for WordPress RSS feed.

Here is the final outcome. Take a look at the Live Demo and download the source code if you want.

Here is the main index.php page code where we are creating SimplePie object and defining RSS feed and functions for extracting thumbnail image link from the feed.

//Including SIMPLEPIE classes and functions
//Creating object of Simplepie i.e $feed
$feed = new Simplepie('');

//This function will get an image from the feed

function returnImage ($text) {
    $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
    $pattern = "/<img[^>]+\>/i";
    preg_match($pattern, $text, $matches);
    $text = $matches[0];
    return $text;

//This function will filter out image url which we got from previous returnImage() function

function scrapeImage($text) {
    $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';     
    preg_match($pattern, $text, $link);
    $link = $link[1];
    $link = urldecode($link);
    return $link;



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $feed->get_title(); ?></title>
<link rel="stylesheet" type="text/css" href="SIMPLEPIE_RSS_SHOWCASE/style.css" />
<link rel="stylesheet" type="text/css" href="SIMPLEPIE_RSS_SHOWCASE/thickbox.css" />
<script type="text/javascript" src="SIMPLEPIE_RSS_SHOWCASE/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="SIMPLEPIE_RSS_SHOWCASE/thickbox-compressed.js"></script>
<script type="text/javascript" src="SIMPLEPIE_RSS_SHOWCASE/script.js"></script>

    <div class="page-wrapper">
        <div class="header">
            <h1><?php echo $feed->get_title(); ?></h1>
        <div class="album-wrapper">
            <?php foreach ($feed->get_items() as $item): ?>
                <div class="photo">
               <?php $feedDescription = $item->get_description();
                    $image = returnImage($feedDescription);
                    $image = scrapeImage($image);
                    $image_url= $item->get_permalink();
                    $image_title= $item->get_title();
                    $post_date = $item->get_date();
//This will print the site title                    
echo '<a href="' . $image_url . '">'. $image_title.'</a>'."\n";
//This will display the thumbnail for each posts
echo '<a href="' . $image_url . '" title="' . $image_title . '"><img src="' . $image . '" /></a>'."\n";
            <?php endforeach; ?>

This SimplePie trick is for WordPress RSS feed. I didn’t try for Blogger and any other blog feeds. Try yourself if you need for any other feeds or put your comments, i will try to incorporate.



The default cache location will be(./cache) in the same location where the PHP file with following code is there and folder should be chmod ‘777’ i.e writable.

//Including SIMPLEPIE classes and functions


SimplePie is already comes with WordPress installation. The functions can be used directly in pages without including ‘’. I will give details instruction on how to use SimplePie in WordPress blog in next post.


This script will display image thumbnails only when if the RSS feed has thumbnails in it. If your WordPress RSS don’t have thumbnails in it then try to add with this tutorial : How to Add Thumbnails to WordPress RSS Feed

Thanks to

Also Read: 6 High Quality Premium WordPress Showcase Themes

, , ,

One Response to How to Display Thumbnail from WordPress RSS feed using SimplePie?

  1. Szafiarka June 4, 2011 at 3:09 am #

    Hello, please take a look at that site… I am using the simplepie example that I found in the WP codex + I added the p> get_description(); ?>

    Can I show the thumbnails of the featured images together with the descriptions of each news?

    Thank you

Leave a Reply