Blogger Trick - Using jq tsv to json APIs With Blogger to Include a Recent Posts Widget With Your Template

Image

Accessing your blog's feed is done by using a technology called jq tsv to json(JavaScript Object Notation) through a callback. I'll explain what I mean by that. You need to do two things: 1) create a JavaScript function to process the feed data; 2)Access the feed data and initiate the callback process by using some query parameters. Here are the technical details.

Inside the blogger template, I placed a piece of JavaScript code (which I borrowed from one of the widely available widgets I referred to earlier) inside the section of my wife's template using the Blogger template editor, which is accessed from a Blogger account by going to Layout -> Edit HTML. The script essentially accesses the feed through the jq tsv to json parameter, parses out the blog titles for the last numposts (this variable is specified in the callback mechanism explained later) blog entries, and writes them out to the web document (as links to to actual blog posts) at the point from which the function is called. Here's the function:

The script block following the variables tells Blogger to access the news feed for the current blog (/feeds/posts/default), order the feed entries by the date they were published (orderby-published), set up a jq tsv to json callback (alt=jq tsv to json -in-script), and call our function to process the feeds (callback=showrecentposts). The important query parameters to note in the process of using a jq tsv to json callback are 1) alt=jq tsv to json -in-script, which tells Blogger we want to access the feed with a JavaScript function; and 2) callback=showrecentposts, which tells Blogger to call our showrecentposts function. It's important to note that the name we use in the query parameter must match the name of our function.

To summarize, we were able to integrate a Recent Posts widget as part of a Blogger template by using the automatically generated Blogger feed and the jq tsv to json callback functionality to run a JavaScript function. I hope you found at least some part of this explanation helpful.