Skip to content

Instantly share code, notes, and snippets.

@MatthaeusHarris
Last active October 31, 2015 02:56
Show Gist options
  • Save MatthaeusHarris/2e8c20795b47c3addf7f to your computer and use it in GitHub Desktop.
Save MatthaeusHarris/2e8c20795b47c3addf7f to your computer and use it in GitHub Desktop.
var feed_url = "http://dragonfinsoup.com/wp/wordpress/?json_route=/posts";
var data;
var masterTemplate;
var fetchPosts = function(num, offset) {
if (!masterTemplate) {
masterTemplate = $('.blogEntry').first().clone();
}
if (!data) {
$.getJSON(feed_url, function(d) {
console.log("Feed fetched.");
data = d;
showPosts();
});
} else {
setTimeout(function() {
showPosts();
}, 0);
}
var showPosts = function() {
$('.blogEntry').empty();
var dataToShow = data.slice(offset, num+offset);
for (var postIndex in dataToShow) {
var post = data[postIndex];
var title = post.title;
var des = post.excerpt;
var content = post.content;
var link = post.link;
var template = masterTemplate.clone();
var $des = $('<div class="linkitem"></div>').html(des);
var $link = $('<a></a>').attr('href',link).attr('target','_blank').html(title);
var pubDate = new Date(post.date);
var day = pubDate.getDate();
var month = pubDate.getMonth() + 1;
var year = pubDate.getFullYear();
var date = day + '/' + month + '/' + year;
var $date = $('<div class="date"></div>').text(date);
var wrapper = "<li class='single-feed'>";
template.find('.blogTitle').html(title);
template.find('.blogBody').html(content);
template.find('.blogDate').html(pubDate);
console.log(title);
$('#blog_content').append(template);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment