WordPress Google Reader Widget

Number 3 in Widget-A-Day is a Google Reader widget.

This widget will display your latest shared stories. You can change the amount of stories to display and how to display them.

Download googlereader.zip

Default display:
googreader1cropped.png

Admin panel:
googreader2cropped.png

Download googlereader.zip

SVN Checkout
svn co http://svn.wp-plugins.org/google-reader-widget/trunk

Requirements

Installation

  1. Download googlereader.zip
  2. Extract and upload googlereader.php to the plugins/ directory
  3. Enable Google Reader in the Plugin admin panel
  4. In widget admin panel, place Google Reader in the sidebar, and edit it to enter your user id

Features

  • Displays your latest shared items from Google Reader
  • Completely customizable display
  • Caching for large traffic sites


User ID

In order to get your shares, you need to know your user id according to Google Reader. This can be found by going to the 'Shared Items' link, and copying the 20 digit number at the end of your shared items link.

So something like:
http://www.google.com/reader/shared/02774557510273097991
Where 02774557510273097991 would be my user id.

Formatting

There are 3 parts needed to format the output.

The first part, called items start in the admin panel, is the first part of the widget after the title. For the default formatting, this is just <ul>.

The second part, called items end, is the ending of the widget. By default, this is:
</ul>
<a href="%googlereader%" style="float:right;">Shared Items</a>

The third part is what is called for each item. By default, this is:
<li style="list-style-type: none;"><a href="%link%">%title%</a></li>

The premise of calling each value is this:

  1. start
  2. item
  3. item
  4. item
  5. end

The formatting for items is:

  • %link% – Link to the item
  • %title% – Title of the item
  • %site% – The title of the site the item is from
  • %sitelink% – The link to the site the item is from
  • %number% – The number of the current item
  • %comment% – The comment (note) made when sharing an item

The formatting for start and end is:

  • %googlereader% – Link to your Google Reader shared page
  • %count% – Number of items shown

Download googlereader.zip

162 Comments

  1. [...] WordPress Widget WordPress Last.fm Widget Widget WordPress Google Reader Widget WordPress Countdown Widget WordPress Weather [...]

  2. Dennis says:

    I just installed this widget, and it works like a charm. But is it possible to get it to show the name of the blog for each item?

  3. James Wilson says:

    Just made a version that does.

    Download the new version, and you can use the variables %site% and %sitelink% to access the site name and url.

    More info – http://nothingoutoftheordinary.com/2007/05/26/wordpress-google-reader-widget/#newversion or just scroll up a little bit

  4. Dennis says:

    Cool, thanks!

  5. Mazoo says:

    Hi,

    I'm new to WordPress and have no coding experience, but I've done a good job in following instructions to fix problems with building my blog so far. The Google Reader widget you've designed works wonderfully on my blog, but I'm having a problem with "& g t ;" appearing where a ">" should appear on news feeds I've posted? (As in "NY Times > Home Page" reads NY Times & g t ; Home Page) You can see it at:

    grottomazoo.com

    Any help you can offer would be appreciated.

  6. James Wilson says:

    Mazoo, your blog's DB is down, but I found and fixed the problem.

    For the RSS feed, all &'s are changes to &amp;, so I changed it to replace all instances to just &, but it'll go back through to make sure the & wasn't just an &amp;

    I added this on lines 58-59:

    $stories = str_replace("&amp;", "&", $stories);
    $stories = preg_replace("/&(?!(amp|[#0-9] |lt|gt|quot|copy|nbsp);)/ix","&amp;",$stories);

    Just download the files again, and replace googlereader.php with the new version.

    Let me know if you encounter any other problems.

  7. Steve Casey says:

    I have created a new Google Reader widget that uses RSS and a widget text box in WordPress. You don't need to do any programming to support it. All the steps are on my site – http://www.chimp-simple.com/2007/06/18/6-steps-to-creating-a-google-reader-rss-widget-in-wordpress/

    Enjoy,
    S

  8. James Wilson says:

    Steve, you didn't really create anything. You're just using what is automatically generated by Google Reader and copying it into a text widget. That relies on Javascript, which means a longer loading time and won't always work. Plus, only so much can be done with it.

    And you don't need any programming knowledge to use this. Knowing HTML can help if you want to customize it though.

  9. micke says:

    This widget looks really interesting, but I can't get it to work. I uploaded it, activated it and I can drag and drop and configure it in the widgets-management. It shows up correctly, and the link to my shared page that is placed at the end is correct – but no items show up at all in the sidebar (except for the "title", "items start" and "items end"-code.

    I have shared four items, which are displayed on my shared items page in Google and when I check the feed from Google, it contains data. Anyone else had this problem?

  10. micke says:

    Ahem. Nevermind. My hosting provider turned off file_get_contents(); for security reasons. I changed the code to use curl(); and voila!, it works.

    Thanks for a great widget!

  11. Norm Gregory says:

    What this is the significance of the "Cache Time?"

  12. James Wilson says:

    It's just the interval that it will check your shared items RSS feed.

    If you set it to 0 or -1, it'll check every page load, which will slow down the page loading time since it has to request and parse the content, instead of just echoing the cached content.

    3600 means it won't check updates if it has checked less 1 hour (3600 seconds) ago. It should be good time for most people.

  13. Norm Gregory says:

    Makes sense. Thanks for the response. And congrats a very nice, easy to use, plug-in. I tried a couple other Google Reader feed widgets. None were as nicely laid out or easy to install/administrate as yours.

  14. James Wilson says:

    Great. Glad you like it.

  15. Mike Pirnat says:

    Very cool – this solves the problem with parsing Atom correctly. Any chance this can get support for multiple widget instances, instead of only getting the one?

  16. [...] may be losing the war at the moment but there's one battle I can win: With some help from the Google Reader Widget for WordPress I've added the contents of my news feed to the right-hand side of the blog. [...]

  17. James Wilson says:

    Mike, thought I responded earlier to your comment, but yes, there should be a multiple widget version soon. I've been working on one for the YouTube widget. Once I get that working and finding the best/quickest way to implement it, I'll probably start adding it to each widget.

  18. kismitt says:

    Google Reader for your cell phone.

    Asterbox.com announces the beta release of their Java mobile platform. They have openly declared what many users have felt: surfing the web on a mobile device is a disappointing experience. Their claims that the internet on the phone is dead, but can live on through web services have been embodied in the Asterbox mobile platform. The Java-based platform utilizes web APIs to deliver content and interactivity to end users in a new and innovative way. The software currently provides access to the Google Reader service, but more functionality is in the works.

  19. jpb says:

    i'm trying to use the Google Reader Widget, and getting this error: Warning: file_get_contents(http://www.google.com/reader/public/atom/user/10503069598462794774 /state/com.google/broadcast?n=9): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /html/wp/wp-content/plugins/googlereader.php on line 55

    line 55 is

    $stories = file_get_contents($uri);

    so i thought that maybe this was the same problem as micke's hosting problem. But when I replace file_get_contents with curl();, it gives me another error:

    Fatal error: Call to undefined function: curl() in /html/wp/wp-content/plugins/googlereader.php on line 55

    Any ideas?

  20. jpb says:

    micke, can you tell me a little more about using curl();? do you have to load libraries or anything? i tried changing the "file_get_contents()" to "curl()" and its not working…

  21. James Wilson says:

    jpb, from the looks of it, it seems you have a space after your user id which makes the url actually http://www.google.com/reader/public/atom/user/10503069598462794774%%20/state/com.google/broadcast?n=9. (only 1 %, since WordPress changes %20 automatically to a space) which doesn't exist, but http://www.google.com/reader/public/atom/user/10503069598462794774/state/com.google/broadcast?n=9 does work.

    Make sure your user id doesn't have an extra spaces or new lines or anything at the end (or beginning). It's saying the actual url is returning a 404, so it not really the function having problems, and using curl, you should still run into the same problem.

    To make sure you don't have that problem, you can change:

    $userid = urlencode($options['userid']);

    to

    $userid = preg_replace("/[^0-9] /ix", "", $options['userid']);

    It will remove all non-numeric characters.

    And to use curl, you don't just use a curl() function, or at least I don't think you do.

    Pretty sure you would have to do something like:

    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$uri);
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    $stories = curl_exec($curl_handle);
    curl_close($curl_handle);
  22. jpb says:

    ah_skeet, yr a saint. Good catch on the trailing space, and thanks for taking the time to lay this all out for me. Be assured that I'll come to you every time I have a technical problem. ;-)

    Thanks again!

  23. James Wilson says:

    Haha, no problem.

    Also, I thought I had fixed this, but somewhere down the line, I broke it again.

    In Widget Formatting, change %site to %site% to display the site name instead of %site.

  24. jpb says:

    Thanks again! I've been poking around, trying to figure that "%site% problem just now. The trailing "%" did the trick.

  25. [...] Nothing to see here… » WordPress Google Reader Widget WordPress google reader shared items widget. Works great. (tags: googlereader widgets wordpress) [...]

  26. Jon says:

    FYI, those who are on a host that doesn't allow file_get_contents…

    here's the exact code you need to slap in there:

    // replacing with cURL
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $uri);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $stories = curl_exec($ch);
    curl_close($ch);

    //$stories = file_get_contents($uri);

  27. I think on line 47
    echo $before_widget.$widgettitle.$options['cache'].$afterwidget;
    should be
    echo $before_widget.$widgettitle.$options['cache'].$after_widget;

    Bye!

  28. James Wilson says:

    @Ivo, right, it should be, but I thought I had fixed that a few versions ago.

  29. Sorry but on line 47 of a fresh downloaded version of the plugin I read $afterwidget and not $after_widget…

  30. [...] All of the weird plugins I'm using now. Dagon Design Sitemap Generator, FeedBurner FeedSmith, Google Reader widget, Google Sitemaps, PXS Mail Form (modified for Akismet), Twitter widget, WordPress.com Stats (which [...]

  31. Thanks for this. Tried two others that didn't have the code that you did for parsing out curly quotes and other sundry HTML nonsense. Very nicely coded and quite handy for simple stuff, or even more complex. Finally someone beat Google at their own game. Thanks a million. I owe you!

  32. posthumous says:

    Thanks for this great plugin and thanks to ah_skeet for the workaround.

  33. Ali says:

    you rock. seriously. i've been messing with rss widgets and feedburner and other crap, all to no avail. this widget worked like a freaking charm. thank you!

  34. Jonathan says:

    I was wondering if this plugin has been tested with WP 2.3.1? Or if their are hacks to make it run?

    I love the idea, and would love to see it progressing. I would be of more help, but my programming skills are novice at best.

    Thanks for your time.

  35. James Wilson says:

    Not been tested, but I think it would work. I don't think they changed too much, especially in the widget part, with the version change.

  36. Mike says:

    Nice! Works like a charm. I was having a lot of problems with the RSS widget. It was taking the URL from the item link and summary xml:base and concatenating them together.

    Anyway, Thanks!

  37. [...] together. I realized this must be a Google-side issue but a quick web search brought me to the WordPress Google Reader Widget. You can see the results in the sidebar. [...]

  38. [...] Nothing to see here? » WordPress Google Reader Widget – This widget will display your latest shared stories. You can change the amount of stories to display and how to display them. [...]

  39. [...] first one found was the Google Reader sidebar widget for WordPress. It's straightforward. Input your Reader ID, # of articles to display, cache time, maybe [...]

  40. [...] Jag använder en widget för att presentera de inlägg jag delar ut från Google Reader, kallad Google Reader Widget. Om någon är intresserad av den och har Loopia som leverantör behövs ett hack i filen, eftersom [...]

  41. Jonathan says:

    As far as I can tell it doesn't work with 2.3.1…if there is a way to get this to work I would be very interested as I love the idea.

  42. micke says:

    Jonathan: doesn't it work for you? I upgraded my installation last week, and I'm running the Google Reader Widget without any problems. Did it work for you before upgrading to 2.3.1?

  43. Charl Botha says:

    Thanks for making this! I'd like to use other Google Reader public feeds (i.e. not always just the Shared Items). Are you planning changes like this, or should I take a bang at it using your code? How are the multiple widget changes coming?

  44. Charl Botha says:

    Okay, I've hacked together a version that takes an arbitrary Google Reader public feed instead of a userid. I've put it up at http://cpbotha.net/thingies/googlereader_arb_feedurl.zip if anyone's interested.

  45. [...] found a widget that will display the feed correctly. It is called Google Reader widget and was written by James [...]

  46. James says:

    @ Charl,

    I wasn't really planning on doing really any changes, unless Google did something to break it.

    The multiple widgets thing were coming, but the way I was doing it got broken in one of WordPress's updates. I'll try working on this break.

  47. [...] in which case your latest posts will appear, via Google Reader, on my sidebar.  I modified the Google Reader plugin so that it can show an arbitrary feed, not just your Shared Items (see my comments on that post for [...]

  48. [...] first one found was the Google Reader sidebar widget for WordPress. It's straightforward. Input your Reader ID, # of articles to display, cache time, maybe [...]

  49. [...] Google Reader widget adds a sidebar widget to show the stories you have chosen to share in your sidebar so no need for the annoying link-list posts (unless you need to add opinion or commentary of course). Configurable via Plugins > Google Analytics. [...]

Leave a Reply