We can pull the post's first label with
Read more »
entry.category[0].term;
. There is no need to get more labels for recent posts. But if we don't add any label on the posts, probably it won't work regularly. The ternary operator has been used to manipulate this problem.
<script>
var numposts = 4;
var isList = true;
function showrecentposts(json) {
for (var i = 0; i < 4; i++) {
var entry = json.feed.entry[i];
var postTitle = entry.title.$t;
var postLabel = entry.category ? entry.category[0].term : "No label";
var postUrl;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == "alternate") {
postUrl = entry.link[k].href;
break;
}
}
postTitle = postTitle.link(postUrl);
if (isList) document.write("<li>");
document.write(postTitle + postLabel);
}
if (isList) document.write("</li>");
}
</script>
<ul>
<script src="//btdocumentation.blogspot.com/feeds/posts/default?max-results=900&alt=json-in-script&callback=showrecentposts">
</script>
</ul>