Creating a Feed Aggregator Page for WordPress with Simplepie

I recently had to work for a client project where i had to pull in rss feeds from various urls and show them in a single page on a wordpress installation,

I first tried to get a free plugin that would do the job. I tried several, but customizing those plugins turned out to be a headache. So i decided to write my own!

Creating an aggregator in wordpress is fairly easy if you have some experience with simplepie – an excellent feed parser script written in php. To make matters easier, simplepie ┬ácomes bundled with WordPress core.

You will need a list of feeds which you want to show in your aggregator page.

Copy paste the following code to any blank php file. Save and upload this file to your active WordPress theme folder.


<span style="line-height: 1.714285714; font-size: 1rem;">"http://www.onebusypixel.com/feed",</span>
<div class="site-content" id="primary">
<div id="content" role="main">

"Graphic Design Blog" =&gt; "http://feeds.feedburner.com/blogspot/Vhqv",
"Dexigner" =&gt; "http://www.dexigner.com/feeds/news",
"Smashing Magazine" =&gt;"http://rss1.smashingmagazine.com/feed/",
"PSD Tuts" =&gt;"http://feeds.feedburner.com/psdtuts-summary",
"You The Designer" =&gt;"http://feeds.feedburner.com/YouTheDesigner",
"Web World ST" =&gt;"http://feeds2.feedburner.com/WebWorldST",
"Design Instruct" =&gt; "http://feeds.feedburner.com/designinstruct",
"Web Design Ledger" =&gt;"http://feeds.feedburner.com/WebDesignLedger",
"One Xtra Pixel" =&gt;"http://feeds.feedburner.com/onextrapixel",
"Hongkiat" =&gt;"http://feeds2.feedburner.com/24thfloor",
"Rebuilding The Web" =&gt; "http://rebuildingtheweb.com/feed/",
);

foreach ( $feed_sources as $index =&gt; $source ) {

$feed = fetch_feed( $source );

echo "
<div class="feed-block">
<ul>";</ul>
</div>
echo "
<h2 class="source-header">" . $index . "</h2>
";

foreach( $feed-&gt;get_items(0,5) as $item ){

$itemlink = esc_url( $item-&gt;get_permalink() );

$itemlink = str_replace( array("http://", "www."), array(""), $itemlink );

echo "
<ul>
	<li><a href="/out/go.php?id=&quot;">" . esc_html( $item-&gt;get_title() ) . "</a></li>
</ul>
&nbsp;

";

}

echo "

</div>
";

}

?&gt;

</div>
<!-- #content -->

<!-- #primary -->

<!--?php get_sidebar( 'front' ); ?-->
<!--?php get_footer(); ?-->

Next go to your wordpress admin panel. Create a new page and select ‘Aggregator Layout’ as page theme. Publish.

Depending on your theme style you may need to modify the structure of this page. You will also need to apply your own css rules.

fetch_feed() is a native WordPress function used to get a feed. This function will open appropriate ports on target location and retrieve the feed. You just need to pass a feed url to it.

The feed array contains list of all feeds which you want to download and parse. If you are parsing a single feed then you can do away with this array and simply pass the target feed’s url to the fetch_feed() function once – you will also need to remove the foreach loop in this case.

This is just a very basic aggregator. I am working on adding a complete admin panel for managing and updating the feeds. Stay tuned to this page.

You can see the demo here: http://www.onebusypixel.com/buzz

VN:F [1.9.12_1141]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.12_1141]
Rating: 0 (from 0 votes)
This entry was posted in General. Bookmark the permalink. Both comments and trackbacks are currently closed.