Display an RSS Feed in Your Theme Without a Plugin

4
Posted April 16, 2011 by Joe DiFiglia in Articles
wordpress-thumbnail-logo



People have different needs for different things, and if your need is to display a simple RSS feed in your theme; there is an easy way to do it… without plugins.  There are a lot of plugins out there for displaying an RSS feed, but many of them actually over complicate things.  Believe it or not, you already have the ability to parse an RSS feed.  Until recently, I had been utilizing RSSImport to accomplish my simple feed requirements, but the fewer plugins we run on our sites, the better.

 

To display a feed on your site, all you have to do is paste the following code in your theme where you would like the feed to be displayed.

<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://computingondemand.com/news/?feed=rss', 20); ?>

Replace the url with the url of the feed you want to parse.  Then replace the 20 with the number of titles you wish to show.

You can get a little more complicated if you like and have the ability to add details beyond just the title to your RSS.

<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://computingondemand.com/news/?feed=rss', 20); ?>

Replace the url with the url of the feed you want to parse. Then replace the 20 with the number of titles you wish to show.

You can get a little more complicated if you like and have the ability to add details beyond just the title to your RSS.

			<ul><?php if(function_exists('fetch_feed')) {
				include_once(ABSPATH . WPINC . '/feed.php'); 						// Includes the necessary files
				$feed = fetch_feed('http://computingondemand.com/news/?feed=rss'); 	// URL to the feed you want to show
				$limit = $feed->get_item_quantity(10); 								// How many items you wish to display
				$items = $feed->get_items(0, $limit); 								// 0 is start and limit is noted above
			}
			if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
			else foreach ($items as $item) : ?>
			<li>
			<div>
				<a href="<?php echo $item->get_permalink(); ?>" title="<?php echo $item->get_date('j F Y @ g:i a'); ?>"><?php echo $item->get_title(); ?></a>
			</div>
			<div>
				<?php echo substr($item->get_description(), 0, 400); ?>
				<p><a href="<?php echo $item->get_permalink(); ?>">[Read More...]</a></p>
			</div>
			</li>
			<?php endforeach; ?><ul>

Note: These functions are not of my own creation, simply things I have found along the way.  If you are the author of this function, please let me know so I can properly credit you with your work!


About the Author

Joe DiFiglia

In early 2000 I became increasingly frustrated with hardware review sites praising less than satisfactory products. The saying: “if you want something done right, do it yourself” applies here. I wasn’t satisfied, so I did it myself; and here we are years later.