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.