Importing Feeds Using WordPress

Not many people know (or maybe they do and don’t talk about it!) that WordPress can actually parse RSS feeds and display them on your WordPress install.

The function we can use is the wp_rss() which will automatically fetch and parse whichever feed you desire and allow it to be viewable to your readers.

So I will show you a quick example of how to use it using Smashing Magazine’s Smashing Network Feed.

I have placed the snippet inside of a class which will allow you to style however you decide, before you start backup your theme files!

In your themes stylesheet add the following:

.sm {margin: 10px 0 10px 0; padding:0;}
.sm ul {list-style:none;margin: 10px 0 10px 0; padding:0;}
.sm li {list-style:none;margin: 0 0 5px 0; padding:0;}

Now in sidebar.php add the following:

<h2>Smashing Network</h2>
<div class="sm">
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://rss1.smashingmagazine.com/feed/?f=smashing-network', 5); ?>
</div>

You can limit the amount of results the feed returns by altering the number at the end of the snippet, for example:

<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://rss1.smashingmagazine.com/feed/?f=smashing-network', NUMBER); ?>

Conclusion

This function can be handy for many things, for example if your part of a blog network you can quickly display items from the blogs network much like the Smashing Magazine example.
Implementation is straightforward and should cause you no real issues, do ensure you backup before playing!

You Might Also Like