Are you looking for a way to fetch an RSS feed and display it in WordPress? While there’s probably a plugin for this, we have created a quick code snippet that you can use to fetch and display RSS feed in WordPress.
Instructions:
All you have to do is add this code to your theme’s index.php file:
<?php if(function_exists('fetch_feed')) { include_once(ABSPATH.WPINC.'/feed.php'); $feed = fetch_feed('http://feeds.feedburner.com/catswhoblog'); $limit = $feed->get_item_quantity(7); // specify number of items $items = $feed->get_items(0, $limit); // create an array of items } if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>'; else foreach ($items as $item) : ?> <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, 200); ?> <span>[...]</span> </div> <?php endforeach; ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 24 best WordPress education themes and how to secure your WordPress forms.
Hello!
The function I was using before was outdated and produced the dreaded Function create_function() is deprecated error. This is working great with all the latest Apache software. Many thanks!
Hey,
Nice but I need to display also the thumbnail, do you know how to ?
Thank you.
You may want to check out: https://www.isitwp.com/add-featured-image-rss-feed/
every time i saw this or similar pages from searching google. no one explained step by step on how to install this. Would be nice if someone would stop expecting everyone to know this and give directions
[…] from your other blog.Drop a RSS news feed in your theme.What other uses would be awesome?[via WordPress Code Snippets] About Eric Dye: I believe in media that matters. I have produced radio for over 15 years, […]