Skip to content

Instantly share code, notes, and snippets.

@louisstow
Created April 10, 2012 04:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save louisstow/2348277 to your computer and use it in GitHub Desktop.
Save louisstow/2348277 to your computer and use it in GitHub Desktop.
Include photo caption
(function(blog, limit) {
limit = +limit || 10;
var scriptTags = document.getElementsByTagName('script');
var scriptNode = scriptTags[scriptTags.length - 1];
var recent = document.createElement("div");
scriptNode.parentNode.appendChild(recent);
recent.setAttribute("class", "widget");
recent.setAttribute("id", "TumblrRecentPosts");
var script = document.createElement("script");
script.src = "http://" + blog + "/api/read/json";
script.onload = function(data) {
if(!tumblr_api_read) return;
var response = tumblr_api_read.posts;
var post;
var len = Math.min(response.length, limit);
var html = "<ul>";
for(var i = 0; i < len; ++i) {
post = response[i];
var title = (post['regular-title'] || post['photo-caption']);
if(title.length > 80) title = title.substr(0, 80) + "...";
html += "<li><a href='" + (post['url-with-slug'] || post.url) + "'>" +
title + "</a></li>";
}
recent.innerHTML = html;
};
document.body.appendChild(script);
})("louisstow.tumblr.com", 30); //enter your settings here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment