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.
Default display:
Admin panel:
SVN Checkout
svn co http://svn.wp-plugins.org/google-reader-widget/trunk
Requirements
- WordPress 2.2 or 2.0.x/2.1.x with WordPress Widgets
- file_get_contents (PHP 4.3.0 or greater) or cURL
- Your Google Reader User ID
Installation
- Download googlereader.zip
- Extract and upload googlereader.php to the plugins/ directory
- Enable Google Reader in the Plugin admin panel
- 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:
- start
- item
- item
- …
- item
- 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
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?
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
Cool, thanks!
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.
Mazoo, your blog’s DB is down, but I found and fixed the problem.
For the RSS feed, all &’s are changes to &, so I changed it to replace all instances to just &, but it’ll go back through to make sure the & wasn’t just an &
I added this on lines 58-59:
Just download the files again, and replace googlereader.php with the new version.
Let me know if you encounter any other problems.
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
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.
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?
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!
What this is the significance of the “Cache Time?”
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.
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.
Great. Glad you like it.
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?
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.
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.
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?
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…
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, buthttp://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:
to
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:
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!
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.Thanks again! I’ve been poking around, trying to figure that “%site% problem just now. The trailing “%” did the trick.
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);
I think on line 47
echo $before_widget.$widgettitle.$options['cache'].$afterwidget;
should be
echo $before_widget.$widgettitle.$options['cache'].$after_widget;
Bye!
@Ivo, right, it should be, but I thought I had fixed that a few versions ago.
Sorry but on line 47 of a fresh downloaded version of the plugin I read $afterwidget and not $after_widget…
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!
Thanks for this great plugin and thanks to ah_skeet for the workaround.
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!
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.
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.
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!
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.
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?
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?
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.
@ 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.