Posted on 18 January, 2010 By Kim Woodbridge 12 Comments

How to Add a RSS Feed Without a Plugin Using the WordPress Fetch Feed Function

 
Share

Fetch (by JJay)

Why back in the dark ages of this site I wrote an article about how to create a delicious bookmarks page. This is a page with a piece of javascript provided by delicious and is pulling my bookmarks that are tagged with WordPress.

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?”

I realized it was a perfect alternative for listing bookmarks rather than using the delicious snippet of javascript.

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.

  1. Change Recent news from Some-Other Blog to a title that makes sense.
    <h2><?php _e('Recent news from Some-Other Blog:'); ?></h2>
    
  2. 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');
    
  3. 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.


Related Posts:
  • How to add a RSS Feed to a Post or Page Using a WordPress Shortcode
  • WordPress – How To Create a Delicious Bookmarks Page
  • How to Show an April Fool’s Day Message on Facebook Using FBML
  • The WordPress Fetch Feed Function and the Feed Cache
  • How to Import Your WordPress Blogroll or Links From One Site to Another
  • Posted In : WordPress Tips
    If you enjoyed this post, please subscribe to my RSS Feed. You can also connect with my Facebook page or follow me on Twitter.



    12 Responses to “How to Add a RSS Feed Without a Plugin Using the WordPress Fetch Feed Function”

    Trackbacks/Pingbacks
    1. The WordPress Fetch Feed Function and the Feed Cache | (Anti) Social Development
    Leave a Comment
    You may use: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

    CommentLuv Enabled

    Recent Comments

      • Ari Herzog: Agreed on the updates/inbox snafu. I rarely see page updates and I know where they are! .-= Ari Herzog´s last blog .....
      • jayson: Kim, Love the themes. I am looking to update the theme on my site to something more appropriate. My site is all abou...
      • vered: "I wish more people would use this. I think it’s silly when I get updates for things occuring in Kansas and California –...
      • Dennis Edell @ Direct Sales Marketing: I was speaking generally, not specifically this month. how exactly do you work things? .-= Dennis Edell @ Direct Sales M...
      • Lucy Beer: Unfortunately I think next to no-one actually sees those "Updates". They're buried in a subsection of the inbox and I do...
      • Kim Woodbridge: Hi Marbella - Thanks! I had a great time....
      • Kim Woodbridge: Hi Julie - I'll probably try kayaking again next summer but I don't know if I will become much of a kayaker - I had a di...
      • Kim Woodbridge: Hi Vered - If you ever get the chance, you should go. It's like a different world - it's so quiet and peaceful....

    About

    Kim Woodbridge is an accomplished Information and Technical Consultant specializing in the entire implementation of a WordPress based website including installation, theme design, upgrades, unique customizations and ongoing site maintenance.

    Wordpress Services

    • Installation, upgrades and maintenance
    • Conversion of existing html and css templates
    • Theme and plugin recommendations
    • CSS customizations
    • Troubleshooting and tweaks for unique situations
    • Customization for individual blogging goals and needs
    • Training and advice