A Web Design Community curated by Chris Coyier

#55: Adding RSS Content with SimplePie

By: Chris Coyier on: 2/25/2009 with 45 Comments

The “Really Simple” part of RSS is sometimes misleading. What if you want to pull in content from an RSS feed and display it on your site? Doing that from scratch would be no-so-easy, but thankfully we have wonderful SimplePie to do the heavy lifting for us. In this screencast we build a really simple site that grabs content from multiple RSS feeds, smushes them together, and displays them using our own custom markup.

Running time: 33:03 minutes

Direct Download: High Quality, Quicktime .M4V Format (AppleTV Ready)

Links from Video:

Get the Flash Player to see this player.

45 Responses

  1. nanochrome says:

    Cool Screen cast Safari 4.0 beat is awesome

  2. Matt says:

    The Safari 4.0 Beta is very nice. I think they use OpenGL on Windows (I think, not sure). Anyways, Simplepie has always been on my favorite list of well made extensions. It gives full editing without fully having to mess with the internals.

    Anyways, I’ll stop the rambling (poor at that) and get to what I really wanted to ask:
    Any chance of touching on Joomla template development? I know you’re giving away the development book, for which I know the publisher is just amazing for their books, but is there any chance that you could pique our interests with some example template design?

  3. Antti says:

    Thanks for the screencast, again! :)

    I agree with Matt; could you perhaps tacle Joomla! the same way you took down WordPress (creating a theme from a PS layout)?

  4. Thanks so much, I finally have the courage to digg my teeth into SP. I didn’t realize it was that easy o_O

  5. benjamin says:

    Great screen cast! I think that it is helpful to know that there is also a SimplePie plugin for WordPress. I think that you can download it from the SimplePie page. Simple Pie is rad and I used it on the bottom of my site (http://benjaminal.com) to just keep up with friends and family whose blogs we follow. The fun part of SimplePie is being able to style the feeds.

    Multiple Twitter feeds are cool too.

    • Todd says:

      Unfortunately, I can’t watch the screencast from my office for some reason (some kind of proxy issue probably) but I’ve tried to use the wordpress plugin in the past and always had issues. Maybe it’s just me though.
      Is it easier to just code in simplepie yourself to a theme?

  6. This is what I did with Simple Pie http://sermons.beimmersed.com let me know if you want the code.

  7. Donna says:

    Thanks Chris! I’ve used magpierss in the past which worked fine for me but this is so much easier! Another great screencast!

  8. kyle says:

    Hey Chris,

    Am I the only one that has issues opening up these videos in itunes? I subscribe to the podcast there, and every so often it simply won’t play. Plays fine here.

    Running Leopard, and the latest version of itunes.

  9. rzea says:

    I checked the code in the demo page, hadn’t seen the screencast yet, and I see the feeds are actually rendered as HTML.

    Can someone confirm this please?

    Thanks.

    • That’s the whole point =)

      It pulls in the feed and renders as HTML so you can style to your heart’s content.

      • Matt says:

        The entire point to glorified RSS =)

        On a side note, does the iPhone/iPod Touch version of Safari have an RSS reader like Safari does on the Mac side? (sleek, blue, easy to scroll through?)

      • rzea says:

        110% agree. More SEO friendly pages with relevant content for the visitors. Awesome!

        Thanks Xris.

  10. Thomas says:

    Nice job on this screencast, Chris! You seemed really natural and relaxed. Great tutorial too, I’m working on a site that will be using this awesome plugin too, can’t wait to show it off! :D

  11. This is Ryan from the SImplePie project. Great screencast! Here are a few additional notes for those following along:

    1) No, loading simplepie.inc doesn’t have a big load on the in-browser code, as it all runs on the server. Also, a large portion of that file size is from code comments. Lastly, it’s important to remember that making things easy is hard. :)

    2) For a PopURLs clone using SimplePie, check out NewsBlocks (http://newsblocks.simplepie.org)

    3) For the IDN folder, if you load it and include the include inside it, SimplePie will support Internationalized Domain Names.

    4) Caching is enabled by default, and writes to ‘./cache’ unless you tell it to write someplace else, and defaults to 1 hour.

    5) $feed->handle_content_type() deals with the character encoding (e.g. UTF-8) for the page. You could also use PHP’s header() function or even the tag to set the output to UTF-8.

    6) Check out some details on cache folder permissions. http://simplepie.org/wiki/setup/setup#step_3

    7) We’ve spent tons of time writing documentation for the entire API. That being said, if something doesn’t quite work the way you expect (such as $item->get_author() which returns another object with sub-methods) read the docs, then hit us up on the support forums. :)

  12. Japh says:

    Great screencast, Chris! I recently used SimplePie in another project, and wrote a tutorial for how to use it with Flickr that’s on NETTUTS+ (http://is.gd/kQ4C)

    Love your work :)

  13. Will says:

    Chris,

    Regarding your comment at about 12:30 into the video when you said “is that an array?” No.

    $feed is an object. When assigning or accessing values in an object you use the -> operator, in an array the operator is =>

    Also, if it were an array it would have been declared as $feed = array(); any time you see $variable = new function(); the keyword new is the clue that you’re creating an object. :)

    • Will says:

      Also regarding permissions…

      If you set the owner of the folder to the username that the web server runs as you can grant write permissions to the user, and leave the rest empty.

      So the permissions would be 600, or 644 (if you want it world readable). there’s no need to have execution access set because you’re not running any cgi scripts from the folder.

  14. Great screencast. I’m interested in your thoughts, as an rss reader and publisher: When does reproducing rss feeds infringe on copyrights? Do you protect your content? Do you obtain permission from authors before reproducing headlines, previews or full articles? Is it fair that some websites are creating revenues (web traffic) from work they didn’t create? Just some thoughts…

  15. Omar says:

    Do you have to create separate feed objects if you don’t want to smush them all together?

  16. insic says:

    thank you for this post. It helps a lot.

  17. Matthew V says:

    How do you diferantiate between 2 or more diffrent feed arrays on the same page for two or more diffrent markups, such as popurls?

    • David Jones says:

      By default SimplePie smushes together all the feeds into one group and sorts it by date, so the feed items are intermingled.

      Actually if you wanted to present 3 feeds seperately as on PopUrls you would be better off using 3 instances of SimplePie.

  18. Wow! You’ve done it again. Basically, your tutorials are shaping all the work I do. Thank you.

  19. Joey says:

    This was very useful. Haven’t been on this website before but hey, let’s add it to my combined brandnew RSS-feed!

    Thanks and keep it going. The tutorial was very clear.

  20. DavidFM says:

    First time in 12 years working online that I’ve watched a screencast all the way through!

    Loving your work (and loving SimplePie).

    Cheers

  21. webninja says:

    Nice tutorial. My first time watching your screencast, would be watching more :)

    One thing though, white spaces above the DOCTYPE trips IE 6 to quirks mode so it might be better to have the tag start right after your first php block. …?><!DOCTYPE…

    Cheers!

    • I have a feeling this is an old wives tale. Not 100% sure though and haven’t run any tests, but there is conflicting stuff out there on if this “whitespace before DOCTYPE triggers quirks mode” thing.

  22. tommy says:

    Nice work, Chris.

    A quick, non-web-related critique:
    Use Audacity or some other audio program (or whatever video software you might be using) to compress your audio so there’s isn’t such a dynamic shift in volume when you’re far away from your mic then get close up.

  23. Gianfranco says:

    Is it possible to setup SimplePie to have a website displaying multiples feeds, but :

    when you click on a feed “item” (permalink), instead of going to the item’s full article on the feed’s website, you dispaly the article on your own website, with your style (and of course you provide a link to the original source / item’s article on feed’s website).

    Kind of, instead of that:
    list of feeds > list of items > original article on feed website.

    That:
    list of feeds > list of items > content > (link to original article on feed website).

    Thanks in advance for enlighting me.

    • jjray says:

      Gian, I hacked it for google news. I was able to do it because google news has a set format for the URL and the same number of characters from the beginning of the feed string until the point where the source URL appears. User the ‘substr’ command in PHP to slice off the portion of the URL string that contains the source URL.

  24. Tresnic says:

    is there a way to set the number of items that are displayed?

    • Tresnic says:

      i know there’s set_item_limit, but that only limits the items from each feed. what if you have a “feedsmusher” and want to limit the number of items that smusher is displaying?

  25. Joe says:

    You can totally tell you’re from Wisconsin. I went to school at Marquette.

  26. Isak says:

    Great video! But please, please, please get another microphone or compress the sound… the volume shifts like crazy :(

  27. adam a says:

    has no one gotten the gzinflate data error running the demo files? i found the issue on simplepie bug list but found no solution. any ideas?

    also trying to pull feeds from digg.com wasn’t working for me till i got the entire rss url for digg. anyone had this issue as well? any ideas? chris’s video and others using digg as an example just use digg.com as the url.

  28. Chris,

    Awesome tutorials. I’ve looking for this information forever. Thanks for all your hard work.

    Can I make one recommendation about the video player. The Viddler.com video player enables you to create a video table of contents. So for example if your tutorial has 5 steps. You can creat a Hyperlink for each step and it will play start playing that part of the video at that specific point.

    It took me forever to to find something you said earlier.

    Be well– and thanks for the insightful video tutorials.

This comment thread is closed. If you have important information to share, you can always contact me.

* This website may or may not contain any actual CSS or Tricks.