One Mom’s Journey from Fat to Skinny to Confident


A Central Mash-Up Using the WordPress Fetch RSS Feed Function

0 Comments 1394 views

A couple of weeks ago Jennifer from asked,

I just had a quick question for you. I love how on your Roni Noone site you have all of your feeds coming in as if it is one blog. How did you set that up? I have a few sites going on at once and I would love a central mash-up like this.

Well Jen you will be happy to hear the answer it pretty easy! It’s driven by your RSS feeds. Here’s a simple tutorial for my fellow self hosted WordPress users.

Fetching the Feed

If you weren’t aware there is actually a WordPress Function called fetch_feed that, yup, you guessed it, fetches a feed.

Here’s the basic syntax


// Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('');
if (!is_wp_error( $rss ) ) :      $maxitems = $rss->get_item_quantity(5); 
    $rss_items = $rss->get_items(0, $maxitems); 

For the code newbie, simply copy and paste those few lines and replace ‘’ with the URL of the feed you want to include on your blog to grab the latest 5 posts.

Displaying the Feed

Once you fetched the feed you can now write code to display it. This is accomplished with a simple loop…

<?php if ($maxitems == 0) echo '<li>No items.</li>';
foreach ( $rss_items as $item ) : ?>
<a href='<?php echo $item->get_permalink(); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a>
<?php endforeach; ?>

Note, this code does not need to be edited at all unless you want to chance the format. It will simply display the 5 items from the feed you identified in the Fetch above.

You can place these two chunks of code anywhere in your wordpress blog (sidebar, index, page, etc.) including in the main loop, like I have here on

Integrated in the Main Loop

A simple way to incorporate RSS elements on your main page between blog posts is to keep a count and pull single items based on that count. For example, in index.php add…

<?php $count = 0; ?>

Somewhere above your main loop which will look something like this..

<?php while (have_posts()) : the_post(); ?>

Then add…

<?php $count++; ?>

Just below the main loop.

This will create a variable called $count and increase it by 1 every time it displays a blog post on your main page.

Now all you need to do is simply check the count and display a feed using a simple if statement. Here’s a simplified version of what is in my index page…

<?php if($count==1) : ?>
$rss = fetch_feed('');
if (!is_wp_error( $rss ) ) : $maxitems = $rss->get_item_quantity(1);
$rss_items = $rss->get_items(0, $maxitems);
<h2> <a href="<?php echo $rss_items[0]->get_permalink(); ?>"> <?php echo $rss_items[0]->get_title(); ?> </a> - <?php echo $rss_items[0]->get_date('n/j/y'); ?> </h2>
<?php elseif ($count==2) : ?>
$rss = fetch_feed('');
if (!is_wp_error( $rss ) ) : $maxitems = $rss->get_item_quantity(1);
$rss_items = $rss->get_items(0, $maxitems);
?> <h2> <a href="<?php echo $rss_items[0]->get_permalink(); ?>"> <?php echo $rss_items[0]->get_title(); ?> </a> - <?php echo $rss_items[0]->get_date('n/j/y'); ?></h2>

<?php endif; ?>

Basically that code checks that count, if it’s 1 then it displays the title of the first RSS item from the GreenLiteBites feed as an h2 and a link. If count is 2, I display the first item in the Roni’s Weigh feed.

If you made it this far you may be asking where the loop is from the "Displaying the Feed" section. Since I only want to display 1 item there is no need to loop at all. I can simply pull the item direction from the array that is created form the Fetch function. You do this simply by using bracket syntax. For example the following code…

<?php echo $rss_items[4]->get_title(); ?>

would display the 5 title in the RSS feed. Always keep in mind counting starts at 0.


The basic Fetch Function is an easy way to start to customize your Wordpres blog. Include the feeds of your other sites, fellow bloggers, or favorite news sources. Almost every site has a feed nowadays. Including a feed in your side bar is a great way to take the leap into wordpress customization and coding.

Leave a comment

I’d love to hear your story or thoughts on mine.

However, to prevent the massive amounts of spam I was receiving I have turned off comments on any post older than 5 days old. If you'd like to leave me a note regarding this post or anything really try me on twitter (@RoniNoone,) my Facebook page, or even IG (@RoniNoone) I'm so sorry for the inconvenience. I never thought I'd have to do this but it's gotten way out of hand and comment management has become simply too time consuming to manage.


There are 0 comments so far.