Darren Hoyt, that brilliant WordPress developer and designer, explains how you can publish RSS feed headlines on your WordPress blog with a built-in WordPress function instead of using a plugin.
As Darren says, this code snippet is not intended for scrapers; it’s for people who have more than one blog, or are part of a blogging network, and would like to have their readers exposed to their other blog material.
The necessary code is what pulls all the Planet WordPress feeds into your WordPress dashboard. Darren took that code from wp-admin/index-extra.php and rewrote it into a snippet which you can insert into your theme files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?php require_once (ABSPATH . WPINC . '/rss-functions.php'); // here's where to insert the feed address $rss = @fetch_rss('http://www.darrensmusicnews.com/feed/'); if ( isset($rss->items) && 0 != count($rss->items) ) { ?> <ul> <?php // here's (5) where to set the number of headlines $rss->items = array_slice($rss->items, 0, 5); foreach ($rss->items as $item ) { ?> <li> <a href='<?php echo wp_filter_kses($item['link']); ?>'> <?php echo wp_specialchars($item['title']); ?> </a> </li> <?php } ?> </ul> <?php } ?> |
Obviously, you have to change the feed address on the fourth line to yours. You can also select how many items from the feed should appear.
In the comments, Darren says that you can publish multiple lists of feeds by copying the snippet with several different RSS feeds. If you want to aggregate a bunch of feeds into one single feed that you’ll republish on your blog, he recommends the Easy Blog Networking for WordPress Blogs plugin, which combines a bunch of feeds and republishes them in one list, or Yahoo Pipes.
Another Option from the WordPress Codex
Scot Hacker brings another variation for displaying RSS feeds on a site: the WordPress function fetch_rss. On the WordPress Codex, you can see an example for displaying a list of links for an existing RSS feed, limiting the selection to the most recent 5 items:
<h2><?php _e('Headlines from AP News'); ?></h2>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://example.com/rss/feed/goes/here');
$maxitems = 5;
$items = array_slice($rss->items, 0, $maxitems);
?>
<ul>
<?php if (empty($items)) echo '<li>No items</li>';
else
foreach ( $items as $item ) : ?>
<li><a href='<?php echo $item['link']; ?>'
title='<?php echo $item['title']; ?>'>
<?php echo $item['title']; ?>
</a></li>
<?php endforeach; ?>
</ul>
Pingback: WPMU Tutorials » 25 New and different ways to use WordpressMU()
Pingback: TalkingApes.com » Blog Archive » Brad’s 2008 Link Extravaganza()
Pingback: Upgraded To Wordpress 2.7 | Lemback Blog - Potpourri of Ramblings()
Pingback: RR [dot] net / How to publish RSS feed into your blog site()