• Home
  • Flailing Wildly
  • Résumé
  • Design
  • Code
  • Wishlist
  • About Me

Flailing Wildly
Too much straw, not enough camel.

Using Del.icio.us Feeds With SimplePie

by Ryan Parman • December 13, 2004 • Projects, Syndication, Technology, Website • No comments

I know that a lot of people are using Magpie RSS to power their del.icio.us sidebar links, so I figured I’d throw out a code sample showing how you could use SimplePie for the same task. If you need to come to terms with why SimplePie might be a better choice of RSS parser, check out the SimplePie project page.

The only other thing that might be worth mentioning is that SimplePie still has a difficult time with non-encoded special characters in feeds and feeds in non-western-european/non-american/non-australian languages. Beyond that, it’s pretty solid so far.

Now, before I get to explaining, I’ll point to a del.icio.us demo with SimplePie in action. Now, here’s the code as a whole:

<?php
include_once("../simplepie.inc");

@ $rss = simplepie("http://del.icio.us/rss/tag/web", false, true, 0.02);

if ($rss != false) {
	print("<p>Reading from " . get_feed_url() . "</p>");
	print("<ul>");

	for ($x=0; $x < 15; $x++) {
		print('<li><a href="' . get_item_permalink($x, $rss) . '">' . get_item_title($x, $rss) . '</a></li>');
	}

	print("</ul>");
}
else {
	print("The del.icio.us feed is not currently available.");
}

print("Powered by " . sp_linkback());
?>

Let’s begin with the first part, include_once("../simplepie.inc");. This is an instance of including the SimplePie library. In my example, the simplepie.inc file is located in the subdirectory.

The next line is where we start processing the rss feed:

@ $rss = simplepie("http://del.icio.us/rss/tag/web", false, true, 0.02);

We start by passing the first parameter, which tells SimplePie where the feed is that we want to process. The second parameter asks whether or not to enable a mode called XMLDump, which we don’t need for this excersize. The third parameter asks whether we want to cache the feed that we’re reading. Since SimplePie currently doesn’t work if the feed isn’t cached (unless it’s a local file), this needs to be true. Lastly, we tell SimplePie how many hours before refreshing the cached feed. We then set the feed to the $rss variable.

Next, we check whether the feed actually exists and was processed. If the expression if ($rss != false) (if $rss is not false…) is true, then we begin displaying the del.icio.us feed.

If you so choose, you can display the URL of the feed you’re using with the get_feed_url() function. I also chose to have this display as an unordered list, since that’s really what it is.

Inside of that <ul></ul> code block, I’ve set up a for-loop. Using $x as my counter variable, I decided to display only the most recent 15 entries. If you want to display all entries in the feed, you can use the get_item_quantity($rss) function.

As a backup plan, I like to add a short message for when the feed isn’t working. In my case, I said that “The del.icio.us feed is not currently available.” Simple and to-the-point.

Next, you want to tell everybody how you made all of this really cool stuff happen by linking back to the SimplePie project page. The easiest way is with the sp_linkback() function.

There! You should now have a fully-functional del.icio.us sidebar right there in your website.

Ryan Parman

Ryan Parman is an entrepreneur, open source evangelist and passionate usability advocate currently living in Seattle. He is the founder and visionary behind SimplePie and CloudFusion, co-founder of WarpShare, member of the RSS Advisory Board, and is currently with Amazon. Ryan's aptly-named blog, Flailing Wildly, is where he writes about ideas longer than 140 characters.

« Happy Birthday, Emily Ann Boydston
God Came Near »

Comments for this post are now closed.

Blog search

Archives
  • 2010 (7)
  • 2009 (7)
  • 2008 (12)
  • 2007 (8)
  • 2006 (18)
  • 2005 (57)
  • 2004 (104)
  • 2003 (103)
Categories
  • Apple (43)
  • Browsers (55)
  • Code (57)
  • Creating Websites (31)
  • Design (5)
  • Digital Media (3)
  • Family Life (10)
  • Just for Fun (25)
  • Music (5)
  • Personal (32)
  • Political (12)
  • Projects (44)
  • Software (60)
  • Syndication (28)
  • Technology (75)
  • Tutorials (5)
  • TV and Movies (16)
  • Video Games (5)
  • Website (62)
  • Work and Business (3)
  • Writing (4)
Socially-aware
  • Twitter
  • Facebook
  • Flickr
  • Last.fm
  • Glue
  • YouTube
  • Delicious
  • LinkedIn
Claim to fame
  • Amazon Web Services
  • WarpShare
  • CloudFusion
  • SimplePie
Legal mumbo-jumbo

All ideas, opinions and comments I post are my own and are in no way affiliated with anybody I work with. If you quote and/or reprint something I've written or said, please direct folks back to this site as a form of attribution. I promise I'll do the same for you. Unless otherwise noted, all content on this site is copyright © 1979–2010 Ryan Parman. Powered by Rocket Sauce.