Skip to content

Instantly share code, notes, and snippets.

@natejacobson
Last active August 29, 2015 14:05
Show Gist options
  • Save natejacobson/7830f7966b08617d9ba8 to your computer and use it in GitHub Desktop.
Save natejacobson/7830f7966b08617d9ba8 to your computer and use it in GitHub Desktop.
Display posts from WordPress JSON api
(function($){
function display_posts( data ) {
var results = data;
var i = 0;
$.each( results, function( index, value ) {
if(index<3){
console.log( value ); // Use this to see what object properties are available, like date, content, etc...
var html = '';
html += '<header>'
+ '<h2 class="article-title">'
+ '<a href="'
+ value.link
+ '">'
+ value.title
+ '</a>'
+ '</h2>';
//var date = value.date;
//var date = $.datepicker.formatDate( 'MM d, yy', date );
html += '<div class="article-meta">'
+ '<time>'+value.date+'</time>'
+ '</div>'
+ '</header>';
html += '<div class="article-tease">'
+ value.excerpt
+ '</div>';
+ '</article>';
$('.home .column.one').append(html);
}
});
$('.home .column.one').append('<hr><a href="/posts">More news...');
}
function pull_posts(e) {
var post_url = 'http://stage.provost.wsu.edu/wp-json/posts/';
$.getJSON( post_url, display_posts );
}
pull_posts();
}(jQuery));
@jeremyfelt
Copy link

$.datepicker.formatDate( 'MM d, yy', new Date( date ) );

Datepicker's formatDate requires a JS Date object rather than a string.

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