So, you have a number of RSS feeds that you follow, and your life would be easier if you could combine them into one that is filtered and sorted to your preferences. For that matter, you might want to put the resulting feed onto a website – say, a home page for yourself where you can see the news you actually care about, instead of what this-or-that company says you should.

You’d do it yourself, but you don’t have the programming skill to make it happen. You’ve searched around the web for that free, magic PHP or CGI script that will combine and sort all your feeds for you, but everything that’s available lacks the functionality you need. Furthermore, due to lax diligence towards standards on the part of the maintainers, many RSS feeds display differently from each other, even using the same parser.

I know your pain. I’ve been there, too. Fortunately, I have the solution for you.

First, I never did find that magic script to do everything I wanted. I did, however, find a solution that is just as good – maybe better. I’d like to introduce you to Yahoo Pipes. This is a service from Yahoo that allows you to plug in as many varied RSS feeds as you like. You can then run them through Yahoo’s filters, checks, and sorters in any manner you like. Pipes will then output a single RSS feed containing only the news you want.

Now, you can use this consolidated feed with any RSS program you like. As an added bonus, Yahoo fixes up all those broken feeds and reformats them in a standards-compliant manner that should work just fine in any reader.

So, how to get this shiny new feed on your website? Keep reading, and I’ll show you how to do something like this:

 

You will need two things: a webhost with PHP support (any host that doesn’t have this isn’t worth your money), and “Magpie RSS”:http://magpierss.sourceforge.net/. If you have experience with PHP, you need not follow these instructions exactly, but if you are new, then deviate as little as possible.

Create two directories on your server in the same location as the page on which you wish your feed to be displayed. Name them “magpierss” and “cache”. Make sure the webserver can write to the cache directory – that means you will have to chmod it to 755, 775, or as a last resort, 777. Head to the above-linked website and download the latest version of Magpie. Open the archive and copy the four .inc files and “extlib” to the magpierss directory.

Now, edit the PHP file in which you wish you display your feed. Cut and paste the following code:

<div style="margin: 0 10px; overflow: auto; padding: 3px; font-family:Times; height:200px; border: 1px solid black;">
<?php
	// Original script by Walter Heitman Jr, first published on http://techblog.shanock.com
	// Include Magpie RSS and fetch our feed
	require_once('magpierss/rss_fetch.inc');
	$rss = fetch_rss( 'http://blog.shanock.com/feed/' );
	// Generate the list
	echo "<ul style=\"padding:0; margin:0px; list-style-type:none;\">";
	foreach ($rss->items as $item) {
		echo "<li style=\"padding:0 0 0 2.8em; text-indent: -2.8em;";
		// Convert publishing date to UTF, and if older than one day, then bold the headline
		$published = strtotime($item['pubdate']);
		if ( $published >= (time() - 86400) ) {
			echo " font-weight:bold;";
		}
		// Print our headline with a short timestamp, generated by the date() function
		// Fix ampersands so that output validates in XHTML 1.0 Strict
		echo str_replace("&","&amp;","\">" . date('m/d', $published) . ": <a href=\"".$item['link']."\">".$item['title']."</a></li>");
	}
	echo "</ul>";
?>
</div>

Permission is hereby given to use, modify, or redistribute the above code in any form or fashion for any purpose, private or commercial, so long as the credit comment is left intact.

 

Now load up the page in your favorite browser and, hopefully, this will give you a nice, clean listing of articles from this website’s feed. The data is cached so that multiple visitors don’t hammer the feed source during high traffic periods. The script will bold headlines of articles that were published within the past 24 hours, and provides a hanging indent for those lines that wrap.

Replace “http://blog.shanock.com/feed/” with the feed of your choice. If you are familiar with CSS and HTML, you should be able to modify the styles, such as width, height, etc., to suit your preferences. If you wish to add more information than just the day and title of a feed item, you can play with the PHP code, and reference Google.

If you have any problems, make sure that all the files are in the right place, and that you pasted the code in a sane location. If you think something is wrong with my instructions, post a comment or let me know, and I’ll fix it up ASAP.

Hope someone found this useful, because I had to learn it the hard way.

UPDATE 13DEC2012: If you receive the error “Deprecated: Function split() is deprecated in /blah/magpierss/rss_parse.inc on line 153”, it is because Magpie RSS is unmaintained, and PHP has since evolved. Navigate to the file and line in question, and change “split” to “explode”. The new function works with the same parameters.

UPDATE 12MAR2014: If you are using WordPress, you will need to put the “magpierss” and “cache” directories in your root. If you want them elsewhere, add a line to the top of the PHP code which defines their location:

        chdir('/path/to/wordpress_root/livedemos/rss');