Search code examples
javascriptphphtmltumblr

How to link to your most recent post on Tumblr?


Possible Duplicate:
How to display a link to my latest Tumblr post using Javascript?

Is there a way for me to link to my latest post on tumblr, bearing in mind the URL will change everytime I create a new post? I've checked the API and I'm having a hard time trying to code a link. Any help would be appreciated!


Solution

  • just read your tumblr rss feed (ie. with php) and use the link of the first item. ie. the url for the tumblr rss feed of "nationalpost" looks like this:

    http://nationalpost.tumblr.com/rss
    

    also the xml api offerts the url for you latest post

    http://nationalpost.tumblr.com/api/read
    

    and also available as json, so you can do it with javascript

    http://nationalpost.tumblr.com/api/read/json
    

    with jQuery it could look like this:

    $(document).ready(function() {
        $.getJSON('http://nationalpost.tumblr.com/api/read/json?callback=?', function(result) {
            $('#link').html('<a href="'+ result.posts[0].url +'">Latest Post</a>');
        });
    });
    

    and here's the working example on jsfiddle