How to merge/mix/combine RSS feeds
One problem I faced on my multi-language blog setup - it has different feeds for each language. Multi-language plugin WPML which I use does not have feature to mix feeds into one. I like my subscribers to see one common feed which is merged for all languages and leave possibility to subscribe to one language also. I setup simple solution using pure PHP.
I did research several times about it and found very few information.
RSS merge for WordPress
Very few plugins exists for WordPress and they do not work with recent 3.X versions. Unfortunately.
Yahoo pipes
Yahoo pipes is a very flexible and feature rich tool for managing RSS feeds. It is possible fetch, merge, split, filter for any RSS source. It has nice graphical interface for all this.
But I think it is a little but overkill for my two feeds.
PHP Solution for mixing RSS feeds
I did not want to bother with PHP coding for such a simple task. But if to compare actual time for coding it is far less then trying different plugins and research.
So I found somewhere on the Internet these two nice libraries:
- magpierss - for fetching feeds
- feedcreator.class.php - for publishing feeds
With a small PHP glue between them I created simple script for merging several RSS feeds into one. Below is simple script that does the job.
You can download full package with libraries included below in the end of post.
<?php /** * Setup part * */ $DOMAIN_NAME = 'http://a32.me/'; $FEED_URL = $DOMAIN_NAME . 'rss/full.php'; $SITE_TITLE = 'a32.blog by Constantin Bosneaga'; $SITE_DESRIPTION = 'Its all about. IT and "stuff" :)'; $SITE_AUTHOR = 'Constantin Bosneaga'; $RSS_CACHE = "/tmp/rsscache"; $RSS_CACHE_EXP = 7200; $FEED_LIST = array( 'http://a32.me/feed/', 'http://a32.me/ru/feed/' ); /** * Do not modify below this point * */ define('MAGPIE_CACHE_ON', true); define('MAGPIE_CACHE_DIR', $RSS_CACHE); define('MAGPIE_CACHE_AGE', $RSS_CACHE_EXP); define('MAGPIE_OUTPUT_ENCODING', 'utf-8'); // include required files require_once ('magpierss-0.72/rss_fetch.inc'); include ('feedcreator.class.php'); /* Set RSS properties */ $rss = new UniversalFeedCreator(); $rss->useCached(); $rss->title = $SITE_TITLE; $rss->description = $SITE_DESRIPTION; $rss->link = $DOMAIN_NAME; $rss->syndicationURL = $FEED_URL; $rss->encoding = 'utf8'; /* Set Image properties $image = new FeedImage(); $image->title = $SITE_TITLE . " Logo"; $image->url = $SITE_LOG_URL; $image->link = $DOMAIN_NAME; $image->description = "Feed provided by " . $SITE_TITLE . ". Click to visit."; $rss->image = $image; */ function showSummary($url, $num = 10, $showfullfeed = false) { global $rss, $DOMAIN_NAME, $SITE_AUTHOR, $SITE_TITLE; $num_items = $num; @ $rss1 = fetch_rss($url); if ($rss1) { $items = array_slice($rss1->items, 0, $num_items); foreach ($items as $item) { $href = $item['link']; $title = $item['title']; if (!$showfullfeed) { $desc = $item['description']; } else { $desc = $item['content']['encoded']; } // $desc .= ' //Copyright © <a href="'.$DOMAIN_NAME.'">'.$SITE_TITLE.'</a>. All Rights Reserved. //'; $pdate = $item['pubdate']; $rss_item = new FeedItem(); $rss_item->title = $item['title']; $rss_item->link = $item['link']; $rss_item->description = $item['content']['encoded']; $rss_item->date = $item['pubdate']; $rss_item->source = $DOMAIN_NAME; $rss_item->author = $SITE_AUTHOR; $rss->addItem($rss_item); } } else { echo "Error: Cannot fetch feed url - " . $url; } } // Fetch all feeds foreach($FEED_LIST as $v) showSummary($v); // Sort items by date function __usort($ad, $bd) {return strtotime($bd->date) - strtotime($ad->date);} usort($rss->items, '__usort'); // Display items $rss->saveFeed("RSS1.0", $RSS_CACHE . "/feed.xml"); |
Download RSS feed mixer/combiner. Unpack and change the Setup part of the script.
WordPress plugin
Want to see this feature as a WordPress plugin? Vote below...
English
Русский
January 9th, 2012 - 05:46
Thanks for posting this. I got this to work, however for each entry in the new feed only displays the post Title and date. The content/excerpt is missing.
here is the feed url:
michaeltchao.com/rss/full.php
and they are fetching the feeds from the following:
michaeltchao.tumblr.com/rss/
blog.michaeltchao.com/feed/
any suggestions?
January 9th, 2012 - 14:45
Yeah, I just did not bother with other fields, because title and content was quite enough for me.
You may check and fix the code include other fields as well, I would update this post with your modifications.
Do you use with WordPress or just standalone ?
January 10th, 2012 - 03:28
I am looking for the same- title and content.
for the site (michaeltchao.com) with the combined feed, i am using wordpress.
and blog.michaeltchao.com is with wordpress as well.
May 9th, 2012 - 01:23
Hi buddy
I am trying add the below two feeds.
‘http://www.amazon.com/rss/new-releases/kitchen/?tag=sioril-20′,
‘http://www.amazon.com/rss/new-releases/music/?tag=sioril-20′
After using given script I am getting feed like this
http://www.clownova.com/rss/full.php
In this I could not able to find ‘?tag=sioril-20′.
Can you please help me in this. How can i make ‘?tag=sioril-20′ available in full.php .
November 23rd, 2012 - 06:33
Would love to see a WP version of this!