WOW RSS is a little PHP script that fetches either a single or multiple RSS Feeds and combines them to display on your website along with categories and dates. With added options, you can tailor the output to suit your needs. If you prefer to use the SimpleXML checkout WOW RSSX.
Table of contents
Prerequisites
The Scripts has been tested on PHP 7.03 and 7.1.12. Slight changes can be made to run on PHP 5.6. Please get in touch if you require help. The script also uses cURL. If you prefer to use SimpleXML use RSSX.
Download
Simply download, extract and place it on your PHP enabled webserver.
Version 1.2 Released- 21st December 2019
How to Use WOW RSS
Once installed on your server you need to include the script on your PHP page.
<?php
include 'wow_rss.php';
//If it's in a subdirectory i.e class
include 'class/wow_rss.php';
?>
Now we need to create a new instance of the class.
If you are using a single class you can:
//Single Feed
$feed = new WowSingleRss($url,$max_items,$date_format,$sort_feed);
//Calling the method to display our feeds
echo $feed->displayRss();
//Multiple Feeds
$combine = new WowMultiRss($urls,$max_items,$date_format,$sort_feed);
//Calling the method to combine and display our feeds
echo $combine->displayRss();
Both WowSingleRss and WowMultiRss take 4 arguments.
$url -WowSingleRss
(String) Required The URL for the single feed you want to fetch.
$urls – WowMultiRss
(Array) Required The URLs of the feeds you want to fetch.
$max_items
(String|Int) Required The number of feeds you want to display.
$date_format
(String) Required The date format you want to display. – See http://php.net/manual/en/function.date.php
$sort_feed
(Array|Bool) Required The order in which you want to sort your feeds. Defaults to newest first if true is set.
Examples -Single Feeds
To display a single feed with the latest 10 items sorted with newest at the top and the date format Jan 18
$url = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$date_format = 'M j';
$sort_feed = array('sort_order'=>'new_first');
$feed = new WowSingleRss($url,'10',$date_format,$sort_feed);
echo $feed->displayRss();
The same can also be achieved by the following
$url = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$feed = new WowSingleRss($url,'10','M j',true);
echo $feed->displayRss();
Display’s a single feed with 20 items sorted with oldest at the top and the date format 1-18-18
$url = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$date_format = 'n-j-y';
$sort_feed = array('sort_order'=>'old_first');
$feed = new WowSingleRss($url,20,$date_format,$sort_feed);
echo $feed->displayRss();
To display 2 single feeds with different options
/*Feed 1*/
$url = "http://feeds.bbci.co.uk/news/rss.xml?edition=uk";
$date_format = 'n-j-y';
$feed = new WowSingleRss($url,5,$date_format,true);
echo $feed->displayRss();
/*Feed 2*/
$url2 = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$sort_feed2 = array('sort_order'=>'old_first');
$feed2 = new WowSingleRss($url2,'5','j F, Y',$sort_feed2);
echo $feed2->displayRss();
Examples – Multiple Feeds Combined
Displays latest 50 items from 3 Combined Feeds with the date format 18 January 2018, sorted by newest first
$url = "http://feeds.bbci.co.uk/news/rss.xml?edition=uk";
$url2 = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$url3 = "http://feeds.bbci.co.uk/news/video_and_audio/uk/rss.xml";
//Above feeds Combined in array for combined multiple feeds
$urls = array($url,$url2,$url3);
$date_format = 'j F, Y';
$combine = new WowMultiRss($urls,50,$date_format,true);
echo $combine->displayRss();
This final example displays the latest 10 items from 3 Combined Feeds with the no date format, sorted by newest first
$url = "http://feeds.bbci.co.uk/news/rss.xml?edition=uk";
$url2 = "http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml";
$url3 = "http://feeds.bbci.co.uk/news/video_and_audio/uk/rss.xml";
//Above feeds Combined in array for combined multiple feeds
$urls = array($url,$url2,$url3);
//If you don't want the date to be displayed leave the string empty
$combine = new WowMultiRss($urls,10,'',true);
echo $combine->displayRss();
Styling Your Feeds
You can optimise the style of your feeds easily using CSS. I have therefore included a CSS file in the download for your reference. The classes to edit are:
wow_feed h2 a{}
.wow_feed h2 a:hover{}
.wow_feed .cat, .wow_feed .date{}
Further Improvements
Furthermore, if you would like to suggest an improvement to the code or request a new feature then please do get in touch. Although the PHP Script has been tested quite thoroughly it shouldn’t contain any bugs. Please report them if you do come across any. Please remember that RSS is quite limited and in order for the script to work you have to have a valid RSS feed(s).
Sources
Stack Overflow – Multiple Curl Requests
Discover more from WorldOWeb
Subscribe to get the latest posts sent to your email.
Hi Tracy, Just wanted to say thanks for this. works nicely.
Hi,
I am trying out your code.
php v 7.3 and curl is installed.
3 rss url strings gives following error:
Warning: array_merge_recursive(): Expected parameter 3 to be an array, bool given in class/wow_rss.php on line 229
Warning: array_walk_recursive() expects parameter 1 to be array, null given in class/wow_rss.php on line 152
using the line:
$combine = new WowMultiRss($urls,50,$date_format,true);
Hi Singh. Do the feeds have dates? Are you able to give me the feed URLs so I can re-produce? Feel free to email them me if you dont want to post.
Fatal error: Uncaught Error: Call to undefined function curl_multi_init() in /var/www/html/rssengine/1/class/wow_rss.php:188 Stack trace: #0 /var/www/html/rssengine/1/class/wow_rss.php(99): WowMultiRss->getFeeds() #1 /var/www/html/rssengine/1/index.php(59): WowSingleRss->displayRss() #2 {main} thrown in /var/www/html/rssengine/1/class/wow_rss.php on line 188
Hi Colby. Is cURL installed?
© 2024 WorldOWeb. All rights reserved