Thursday , 24 April 2014
Home | Articles | Wordpress | Display an RSS Feed in Your Theme Without a Plugin
Display an RSS Feed in Your Theme Without a Plugin

Display an RSS Feed in Your Theme Without a Plugin

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 Joe DiFiglia

I have always had a passion for everything computing. In early 2000, I decided to take my passion to the web. Thus, C.O.D. was born. Through the years we have made many great friends at C.O.D. and hope to continue our journey for years to come.