Last active
October 31, 2015 02:56
-
-
Save MatthaeusHarris/2e8c20795b47c3addf7f to your computer and use it in GitHub Desktop.
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
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