Well, call me dense but there is a WordPress function called Fetch Feed that can be used to do the same thing and can actually be used to pull any RSS feed to your templates without the use of a plugin.
Sometimes I wonder why it takes me so long to notice things like this. I guess I don’t really study everything WordPress can do unless I am specifically searching for a solution.
Anyway, I was going through my feed reader, which is a rare occurrence these days, and came across this article about adding a flickr gallery to WordPress without a plugin. And I thought, “why didn’t I realize this function existed?” and “what could I use it for?”
The code provided by the Codex as an example is the following:
<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://example.com/rss/feed/goes/here'); // 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); ?> <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> </li> <?php endforeach; ?> </ul>
Now I’m sure you’re all thinking, “Ok. That’s great Kim. Thanks for throwing that load of goop at us.” But, it will work fine with most templates and only two parts of it need to be changed.
- Change Recent news from Some-Other Blog to a title that makes sense.
<h2><?php _e('Recent news from Some-Other Blog:'); ?></h2>
- And you put the url to your feed where it says http:http://example.com/rss/feed/goes/here
// Get a SimplePie feed object from the specified feed source. $rss = fetch_feed('http://example.com/rss/feed/goes/here');
- You can also change the number of items that are pulled by the feed but that isn’t necessary. Change the 5 to the number of items that you want.
// Figure out how many total items there are, but limit it to 5. $maxitems = $rss->get_item_quantity(5);
When I started this post I mentioned using fetch feed to pull delicious bookmarks. I got the rss feed for my bookmarks with the tag wordpress and placed it in the footer of this page. If you scroll down to the bottom you will see the result of the code in the footer. This could be used in sidebar widget, if you are also using a plugin like Exec-PHP that allows code in text widgets or you could create a custom page template to display feeds.
Can you think of interesting uses for this? So far, I’ve been thinking about a custom news page or a custom lifestream page that pulls in feed from the social networking sites that you use.
Sidenote: I used to have a cat that would fetch. If I shot a rubber band across the room, she would chase it, pick it up in her mouth and bring it back to me so I would throw it again.