Skip to content

Instantly share code, notes, and snippets.

@krzysu
Created January 30, 2013 11:55
Show Gist options
  • Save krzysu/4672824 to your computer and use it in GitHub Desktop.
Save krzysu/4672824 to your computer and use it in GitHub Desktop.
Wordpress: display N posts on static page from RSS source
<?php
$rss = fetch_feed( 'http://www.ondango-labs.com/feed/' );
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
?>
<div class="three-from-four" id="latest-posts-box">
<?php foreach($rss_items as $index => $item): ?>
<article class="one-from-two element <?= ($index % 2 == 1) ? 'last' : '' ?>">
<h2>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>" title="<?php echo $item->get_title(); ?>">
<?php echo $item->get_title(); ?>
</a>
</h2>
<div class="element-body">
<?php echo $item->get_description(); ?>
</div>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment