Embed RSS Feeds in WordPress

WordPress makes it easy (well, kind of) to embed RSS feeds into your WordPress template, so you can have a feed displayed in your sidebar, footer, or anywhere else you want in your PHP files. To do this, I used a combination of code from Darren Hoyt and Jeriko.

first, from Darren

<?php
require_once (ABSPATH . WPINC . '/rss.php');
$rss = @fetch_rss('RSS FEED HERE');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<ul>
<?php
$rss->items = array_slice($rss->items, 0, NUMBER OF ITEMS);
foreach ($rss->items as $item ) {
?>
<li>

and then the bit from Jeriko

<a href='<?php echo wp_filter_kses($item['link']); ?>'>
  <?php echo wp_specialchars($item['title']); ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>

  • Digg
  • Facebook
  • Google
  • TwitThis
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Mixx
  • E-mail this story to a friend!
  • Print this article!

Related posts:

  1. Speed Up WordPress Blogging with HTML
  2. Gmail RSS Feeds
  3. Install WordPress on Your Desktop!
  4. Add Author Image (Gravatar) to Posts
  5. Add “All Posts” Archive Page to WordPress Blog

Enjoy the post? Encourage me by subscribing to the feed, following me on Twitter, and becoming a fan on Facebook. Cheers!