I aggregated all my new posts from several sites into a single RSS feed. Last time I updated my homepage, I came across an idea why not showing these feed items directly on the homepage as HTML content. After some study, I got one single PHP function in my hand that fetches an RSS feed and outputs HTML content in the page.
The PHP fuction and one example are as follows.
The single PHP function that gets RSS feed and converts it to HTML. Another helper function that outputs the HTML content.
One usage example:
<?php // output RSS feed to HTML output_rss_feed('http://feeds.systutorials.com/ericfeed', 20, true, true, 200); ?>
The comments in the code should explain what it does well. You can call the
output_rss_feed with the feed link and other options at the place where you would show the RSS feed.
This function also supports a simple caching mechanism so that not every call to the same RSS feed will invoke a network request. Note that there is no cache in this function and there is no planned future work to add the cache here. If you do meed the cache in a high volume site, consider adding a local cache system that caches the RSS feed and provide the function the new RSS address from your local cache system.
For the style of the items displayed, you may customize your site’s CSS file or add add a style tag to control the styles.
Latest posts by Eric Zhiqiang Ma (see all)
- Vim Tutorial for Beginners: vimtutor - Dec 31, 2016
- Essential Gnome Shell Extensions for Gnome 3 Users - Oct 22, 2016
- How to Install 32-bit Wine 1.8 on CentOS 7 - Oct 16, 2016