Home » Labs » Fetch and display RSS in WordPress  

Fetch and display RSS in WordPress

Filed under Labs

Copy and paste below code in your WordPress template then the code will display the title and description of most recent feed item according to the number which set in variable ‘$items’.

include_once(ABSPATH.WPINC.'/rss.php'); // path for including include
$feed = fetch_rss('http://mydoamin.com/feed/'); // specify your feed url
$items = array_slice($feed->items, 0, 20); // specify the numbers of items to display
<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>
<h3><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></h3>
<p><?php echo $item['description']; ?></p>
<?php endforeach; ?>
<?php endif; ?>

Posts you may like: