-
-
Save wachen/3836381 to your computer and use it in GitHub Desktop.
Include photo caption or link text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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'] || post['link-text']); | |
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); | |
})("yourtumblrnamehere.tumblr.com", 5); //enter your settings here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment