Created
October 30, 2009 14:25
-
-
Save cdmoyer/222366 to your computer and use it in GitHub Desktop.
How to integrate your tumblog into your site via their jsonp api.
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
<!-- <head> if jquery isn't on the page already --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> | |
<!-- <head>, another file, wherever --> | |
<script type="text/javascript"> | |
function tumblr(resp) { | |
var posts = resp.posts; | |
$('#blog .loading').replaceWith('<ul/>'); | |
$ul = $('#blog ul'); | |
for (var i=0; i<posts.length; i++) { | |
var p = posts[i]; | |
var title = p['regular-title'] || p['link-text'] || null; | |
if (title) | |
$ul.append('<li><a href="'+p['url']+'">'+title+'</a></li>'); | |
} | |
} | |
</script> | |
<!-- Where you want your tumblog --> | |
<div id="blog"> | |
<h2>My Blog</h2> | |
<span class="loading">Loading...</span> | |
</div> | |
<!-- Bottom of the page, probably. Change host --> | |
<script src="http://YOURTUMBLOGHOST/api/read/json?callback=tumblr&num=10" type="text/javascript"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment