Last active
August 29, 2015 14:05
-
-
Save natejacobson/7830f7966b08617d9ba8 to your computer and use it in GitHub Desktop.
Display posts from WordPress JSON api
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
(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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$.datepicker.formatDate( 'MM d, yy', new Date( date ) );
Datepicker's
formatDate
requires a JS Date object rather than a string.