Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Merge multiple RSS feeds with SimplePie
/* Merge multiple RSS feeds with SimplePie
* Just modify the path to SimplePie and
* modify the $feeds array with the feeds you want
* You should probably also change the channel title, link and description,
* plus I added a CC license you may not want
* Help from:
header('Content-Type: application/rss+xml; charset=UTF-8');
// Your path to simplepie
include_once('/path/to/simplepie/'); // Include SimplePie
$feedlink = ""; // URL for this feed, <atom:link>
$feedtitle = "Jon's Feeds"; // <title>
$feedhome = ""; // <link>
$feeddesc = "One Feed to Aggregate Them All"; // <link>
// Feeds you want to aggregate
$feeds = array(
echo '<?xml version="1.0" encoding="UTF-8"?>';
<rss version="2.0"
<title><?php echo $feedtitle; ?></title>
<atom:link href="<?php echo $feedlink; ?>" rel="self" type="application/rss+xml" />
<link><?php echo $feedhome; ?></link>
<description><?php echo $feeddesc; ?></description>
<copyright>Copyright <?php echo '2007-'.date("Y"); ?></copyright>
$feed = new SimplePie(); // Create a new instance of SimplePie
// Load the feeds
$feed->set_cache_duration (600); // Set the cache time
$feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false);
$success = $feed->init(); // Initialize SimplePie
$feed->handle_content_type(); // Take care of the character encoding
<?php if ($success) {
foreach($feed->get_items() as $item) {
if ($itemlimit==40) { break; }
<title><?php echo $item->get_title(); ?></title>
<link><?php echo $item->get_permalink(); ?></link>
<guid><?php echo $item->get_permalink(); ?></guid>
<pubDate><?php echo $item->get_date('D, d M Y H:i:s T'); ?></pubDate>
<dc:creator><?php if ($author = $item->get_author()) { echo $author->get_name()." at "; }; ?><?php if ($feed_title = $item->get_feed()->get_title()) {echo $feed_title;}?></dc:creator>
<?php echo htmlspecialchars(strip_tags($item->get_description())); ?>
<content:encoded><![CDATA[<?php echo $item->get_content(); ?>]]></content:encoded>
$itemlimit = $itemlimit + 1;
Copy link

DigitalFreelancing commented Sep 15, 2019

On line 16, if you are running a more recent version of simplepie, just change this:

include_once('/path/to/simplepie/'); // Include SimplePie
to this:

(my autoloader.php file is in ./php/, if yours is in a different place, just change the path)

For people who doesn't know how to make this work with SimplePie I created a tutorial step by step from the beginning:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment