Javascript API for wordpress posts

I have been looking at ways of using my activity stream. The stream is a WordPress blog and has various kinds of data (status msg, pictures, links and posts). Eventhough wordpress provides certain xml based APIs, I wanted something simple, that works on client side.

One of the requirement was to pull the latest mobile picture post, to display on my main blog. By default wordpress provides RSS feed for each author, category and tag. It wasnt that difficult to get the latest post but it is difficult to use XML in JavaScript. JSON seemed more useful than RSS. In the mean time Dave Winer was also thinking on similar lines. I thought about writing a plugin to convert RSS feed into JSON feed. But then whole wordpress family seems to like Dave (Remember WP.com supports RSS cloud). So I searched wordpress plugins. I found the one which I wanted – Feed JSON .
So it gives me JSON feed for my mobile picture stream and also has call back feature.

http://thej.in/?feed=json&author=4
//with callback
http://thej.in/?feed=json&callback=mymethod
&author=4

It also works with permalinks if that is enabled in wordpress. Here comes my widget for latest camera pics.

<script>
function writeWidget(posts){
alert(posts[0]["title"]); 
}
</script>
<script src="http://thej.in/?feed=json&author=4&
callback=writeWidget">
</script>

Now with this its easy for any wordpress blog to create JavaScript based widgets, that can be embedded any where on the web. Well for some use cases the full content JSON could be heavy. So try it before you widely deploy. Let me know what you think.

You may also like...

1 Response

Leave a Reply

Your email address will not be published. Required fields are marked *