Skip to content

Instantly share code, notes, and snippets.

@digitalmud
Forked from alicial/recent-tumblr-posts.js
Last active December 12, 2015 07:09
Show Gist options
  • Select an option

  • Save digitalmud/4734631 to your computer and use it in GitHub Desktop.

Select an option

Save digitalmud/4734631 to your computer and use it in GitHub Desktop.
// Add <ul id=”recent-posts”></ul> to your blog to demark where you'd like the list to appear.
//
// Needs jQuery. Place the javascript below *after* your jQuery include.
<script type="text/javascript">
$(function() {
// This script uses your tumble blog's RSS feed. The URL is usually in the form yoursite.tumblr.com/rss
var url = '/rss';
var $list = $('#recent-posts');
$.ajax({
url: url,
type: 'GET',
dataType: 'xml',
success: function(data) {
var $items = $(data).find('item');
$items.each( function() {
var $item = $(this);
var link = $item.children('link').text();
var title = $item.children('title').text();
if (link && title) {
$list.append($('<li><a href="' + link + '">' + title + '</a></li>'));
}
});
}
});
});
</script>
Copy link

ghost commented Feb 17, 2013

Hi. I'm totally new to both JS and GitHub. Can you tell me how to make this thing work only for 5 posts? I mean, there must be some way to limit the function(data) call to 5 posts only... but I dont know where to get that thing done. Would be great if you could help me out :) Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment