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

Best Items - Best Restaurant WordPress Theme

Collection of best Premium restaurant WordPress themes ready to be used for your and client projects.

Best Items - Top e-Commerce WordPress Plugins

Find 61+ top notch e-Commerce WordPress plugins - Paypal, Jigoshop, Amazon, WooCommerce, Credit Card Gateway and Authorize etc.

Best Items - Best WordPress Templates Made for Mobile and Tablet Visitors

Collection of Premium WordPress templates to take your website to the next level. Use these themes on your project to reach out Mobile and tablet users. Grow your business and traffic instantly.

Best Items - Top notch Premium BuddyPress Themes

Are you looking for best premium WordPress themes which are BuddyPress ? Head over to Premium BuddyPress Themes for top quality and responsive designs.

Best Items - Collection of Best Premium Portfolio WordPress themes

Need to showcase your project work in a stunning way? These premium Portfolio WordPress themes will make your work easy for you. Perfect for showcasing Project, Photography, Video and Art work.

Best Items - Ultimate Collection of Responsive WordPress Themes

Responsive WordPress themes enables stunning look and feel of your website in any device - from mobile devices to widescreen monitors. These collections are sorted by user rating and number of sales.

Best Items - Top Selling WordPress Themes From Themeforest

Want to use one of the top selling WordPress theme for your next project?   Here is the list of Premium WordPress items from Blog, Magazine, Creative, Retail, Technology, Entertainment, BuddyPress, eCommerce and Nonprofit categories.

Best Items - 70+ Premium elegantThemes for Just $39

Unlimited access to 70+ elegantThemes - Premium WordPress themes for only $39. Feature includes - ePanel Theme Options, Shortcodes, Page Templates and Easy Localization. Power your website with elegant themes today!

, , ,

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