How to use default WordPress RSS widget in your php templates

I showed you how to use widgets using the_widget in your php templates before. Upon request, I am going to show you how to use WordPress RSS Widget with the help of WordPress the_widget function.

It’s quite simple actually, all you need is the URL of the RSS Feed and number of items to be displayed. Here is the snippet to display feed items using php:

<?php
   if(function_exists('the_widget')) { // If the_widget is supported
		$rss_options = array( 
			'title' => 'Test',  // Title of the Widget
			'url' => 'http://shailan.com/feed/', // URL of the RSS Feed
			'items' => 10, // Number of items to be displayed
			'show_summary' => 0, // Show post excerpts?
			'show_author' => 0, // Set 1 to display post author
			'show_date' => 0 // Set 1 to display post dates
		);
	
		the_widget('WP_Widget_RSS', $rss_options);
   }
?>

You can either put this code in a sidebar template, or maybe to a page template if you like. Just copy and paste the code, and then edit URL and item count options. Then you will have a widget displaying feed items as a list.

[contact-form-7 id=”4339″]