Skip to content

Instantly share code, notes, and snippets.

@madeinnordeste
Created March 1, 2015 15:18
Show Gist options
  • Save madeinnordeste/4f882b0a4b70e9b48572 to your computer and use it in GitHub Desktop.
Save madeinnordeste/4f882b0a4b70e9b48572 to your computer and use it in GitHub Desktop.
Wordpress: Fetch RSS feed
<?php
//see: http://codex.wordpress.org/Function_Reference/fetch_feed
//see: http://simplepie.org/wiki/reference/start#simplepie_item
?>
<h2><?php _e('Recent news from Some-Other Blog:'); ?></h2>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed('http://feeds.feedburner.com/euqueroserummacaco/madeinnordeste');
if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity(5);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo $item->get_permalink(); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a>
<hr /><hr /><hr />
</li>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment