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 responses to “WordPress Google Reader Widget”

  1. is there a way to show the title and excerpt on the sidebar without the title link? how do i remove the title’s URL? i prefer no URLs on the sidebar.

    on my site, instead of seeing the list of 10 shared items, i see a text link that says shared items. how do i show the list?

  2. Hi James,

    Thanks for this widget. I was just wondering if there is a parameter that will allow me to include the image for the article on my page. Most of the shared items have an image with them when I post to my facebook page, so I know they’re in there somewhere ๐Ÿ™‚

    Thanks

  3. […] instances of the same thingย due to the linkages between my social presences. I also found a Google Reader widget/plugin which I like the output of better than just using the RSS feed of my shared items. And I finally […]

  4. Hello,
    For some reason the plugin stopped working on my site – it doesn’t pull anything from google news anymore (so more li items), but it does show the header and “more news…” link, so something is still up and running.
    Is there a way to delete or reload the cache?

    Cheers, TC

  5. Ah, I got it, thanks!
    Setting the cache to -1 and back to 7200 helped, too. The actual problem was the get_file_contents function that my host’s PHP installation didn’t support. As you mention correctly on the FAQ page (and I should have read it!), I had to use
    $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);

    The last automatic update deleted these changes, I think ๐Ÿ™‚
    Thanks for the quick reply.

  6. This is a very nice widget … and I’ve enjoyed looking back at your widget a day endeavor. But you never responded to Josh Fialkoff above, and I have the same question. I’m looking for a way to display shared items on a single page within WordPress (with a “more” tag at the bottom to scroll through entries). It would be nice if users did not have to leave the site to “read more” when looking at items in sidebar!!

    Josh Fialkoff says:
    October 9, 2008 at 9:43 pm

    Hi,
    I am trying to make a dedicated page for my Google Reader shared items.

    Is it possible to insert this into a page, rather than into the sidebar?

    Thanks,
    Josh

  7. This widget currently, I don’t think it’s possible. It should possible to port it to be able to do that.I’d have to look at documentation to figure out how it would be done.

    A read more link added to the widget shouldn’t be too bad using javascript.

  8. Great widget, but I noticed one thing. I often use HTML markup in my comments, and noticed that when comments were spit out in the widget that any HTML entities were being printed out instead of used as real markup (such as a break tag). To get around it I added an html_entity_decode around the $comments var in the “// Comment hack, [email protected]” (line 93 normally, line 100 with the curl version) section.

    So
    $comment = $matches[1];

    Became
    $comment = html_entity_decode($comment);

    In case anyone else runs into that.

  9. How often does the RSS pull from your reader account. I’m guessing this is related to the cache value you set?

  10. Thanks for the reply. So how to i determine what the cache value should be in order to get more frequent updates?

  11. Great plugin! I am using it already on a company blog. Got a question:

    Is there a way to use two Google reader widgets on the same blog?

    I did the obvious thing and tried to install two Google Reader plugins but got a fatal error and had to delete the second. Is there a proper way to do this?

  12. Oh, one other thing. I looked everywhere in Google Reader and could not find it.

    Does anyone know how to automatically subscribe to a RSS feed?

    I am trying to add a quote of the day function and want the reader widget to automatically show the latest quote.

  13. James,

    1/ you could use Google Reader Trends to see how many items you share per day and estimate the number of shared items per our hour (depending how often during the day you read your RSS feeds).

    2/ You could also use an website analytic tool (google analytics, quantcast, wordpress statistics, etc.) to see how often users return or how long they spend on the site. Maybe you want to show them something new while they are on your site, or maybe only when they visit again so they don’t go hunting for that article headline that they just discovered and wanted to read later and suddenly it’s gone…

    3/ You could measure the total server-side loading time of a page (see my blog http://www.playoutintelligence.com at the very bottom right hand side – click on the numbers to get a feedjit window if you use Firefox). Now start playing with caching times of 60 seconds and see if that really makes a difference. Maybe you give a ^&*# if the loading time is 2 seconds or 0.5 seconds ๐Ÿ™‚

    4/ You could just leave it with the default and worry about something else… ๐Ÿ™‚

  14. @James, thank you. Using curl eliminates the error, but no content is shown. I’ll give it about 15 minutes to see if it starts to pull content…

  15. James, thanks, I’ll give that a try. I’ve opened a support ticket with my host, as there may be something going on that blocks fetching external content. I’ll dig into this more later today and tomorrow. Thanks very much for your quick replies!

  16. James, I reinstalled version 1.9.0 and it works fine. Web host reports no problems fetching external content. Widget version 1.9.1 is not working for me. I’m running on a BSD operating system.

  17. James, your link didn’t seem to work, so I ran a diff on my host. Looks like the $stories variable in 1.9.0 is removed in 1.9.1?

    I’ll paste part of the diff here, hope it survives formatting ๐Ÿ˜‰

    — begin paste —

    Version: 1.9.1
    12a13
    > 1.9.1 – Added curl fallback support.
    62c63,73
    if(function_exists(“file_get_contents”) AND $options[‘use’] != “curl”) {
    > $stories = file_get_contents($uri);
    > }
    > else {
    > $ch = curl_init();
    > curl_setopt ($ch, CURLOPT_URL, $uri);
    > curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    > curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
    > $stories = curl_exec($ch);
    > curl_close($ch);
    > }
    163a175
    > $options[‘use’] = stripslashes($_POST[‘googlereader-use’]);
    187a200
    > echo ” . __(‘Use:’, ‘widgets’) . ‘ echo ‘ echo ‘Help Development – Donate</p$

    — end paste —

  18. James, nope, every line with a left bracket in the diff is stripped from the comment. In the diff pasted above, just before the if(function_exists) test, my diff showed the following as present in 1.9.0 but removed in 1.9.1 (more in a moment):

    $stories = file_get_contents($uri);

    Now I know it is in the IF statement, which makes me wonder if the IF test is failing on my platform, so that it never gets to the $stories variable in version 1.9.1.

    Hope that made sense!

  19. James, I took a whack at the code in 1.9.1. This change works on my system, with the file_get_contents selected and when I select curl. (Apologies: it’s been a while since twiddled with PHP…)

    — begin paste —

    if(function_exists(“file_get_contents”)) {
    if($options[‘use’] = “file_get_contents”) {
    $stories = file_get_contents($uri);
    } else {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $uri);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
    $stories = curl_exec($ch);
    curl_close($ch);
    }
    }

    — end paste —

  20. Tom, that will fail on any systems without file_get_contents, which is what the curl is supposed to fix. And checking that it’s not curl, and not just equal, allows for it to fallback to file_get_contents if the option isn’t set or is something different, which an update to the plugin without setting the widget again would do.

    It should be doing this:
    If no file_get_contents => use curl
    if use option == curl => use curl
    if file_get_contents works and use isn’t curl => file_get_contents

  21. James, yes, I know my hack is not ideal. But now the widget works for me, at least for now. While I don’t look forward to modifying the widget code with each release, I will do so if necessary because I really like this widget ๐Ÿ™‚

    Be well,
    Tom

  22. Hi James. Downloaded fgc.txt, uploaded, renamed to fgc.php. Running that without parameters returns FGCFGCFGC. Running with the opt=1 parameter returns CURLCURLCURL.

    I’m stumped, because your IF statements in the widget look fine to me. Thus, I don’t grok why it didn’t work for me.

    On the other hand, if I’m the only one on the planet having this problem, it doesn’t make sense to try to fix the widget for one instance. I can live with it, adjusting as needed.

  23. Initially this widget did not appear to work, showing just the “Shared Items” link (which did work), but articles. Took a moment to realize I should set “curl” instead of “file_get_contents” under ‘Use:’. Now works like a charm. Thanks!

  24. Hey,

    Thanks to you I now have a really great tool to display my highlighted stories from my Google Reader to my blog visitors, never really had much use directly for the Shared Page, but now it will work wonders!

    Thanks for the great plugin

    Josh Chandler

  25. My problem is that, every now and then, the User ID changes from ‘05831227970666788992’ to another number and I have to reset the number frequently in the widgets panel. What is wrong?

  26. any thoughts the Categories, Tags, Bloggers, and Archives section and how that would work if we were just pulling blog entries from a Google Reader account?

  27. I’m having the same problem as Pablo, using WordPress 2.8. The widget resets the ID and the cache time every time I return to my admin panel. Any suggestions?

  28. Thanks for this widget, James; I’ve been using it for about 6 months now, but after upgrading to WP 2.8.2, it no longer appears compatible – it just plain doesn’t show up on my site ( http://www.damianbariexca.net ; should be underneath the Shelfari widget on the far right). Any updates coming, or do you suggest a specific workaround I can implement in the meantime?

    Thanks much for your hard work!

  29. I’ve figured out my problem – I thought I had to put in the new “vanity” URL into the widget since I have that enabled in my GR Shared Settings. Turns out the numerical URL works just fine, even with the vanity URL enabled.

    Thanks again!

  30. Heh, sorry for the triple posting, but I’m now having the same problem as bingregory and Pablo above – the ID resets constantly now; this occurs with v1.9 and v1.9.1 of the plugin. I’m using WP 2.8.2.

    Thanks!

  31. James,

    I would like to call the reader function in my code rather than as a widget. Can you give me some sample code for that. I can’t quite figure out the arguments and how they need to be passed. Sorry, Im new to PHP, but love wordpress.

    Thanks

    Joe

  32. hi, i love this widget…though it doesnt seem to update unless i go to the widgets panel and ‘save’ the Google Reader Widget. any suggestions?

Leave a Reply

Your email address will not be published.