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 NonProfit WordPress Themes

Are you looking for WordPress themes for Nonprofit organisation such as Churches, Charity or Environmental? Find top quality WordPress themes designed specifically for Churches, Charity, Politicians, Environmental and etc.

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!

Best Items - Best Real Estate WordPress Themes

Need to design Real Estate Website for your client ? These collection can make your life easy while developing Real Estate websites for your client. Choose from wide verity of WordPress templates and make your own unique design.

Best Items - Recommended WordPress and Web Development Books

Want to learn IN and OUT of web development and become professional web developer? Here are the list of WordPress and Web Development books which i recommend you to start with.

Best Items - 200+ Popular HTML Email and Newsletter Templates for Effective Marketing

Do you want to market your products effectively ? There are 200+ great collection of E-mail and Newsletter HTML templates from Themeforest. Get into site directly and search for the suitable template that boost your sales and conversion rate.

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 - 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 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.

, , ,

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