Skip to content

Instantly share code, notes, and snippets.

@vsitaraman
Last active June 10, 2021 19:09
Show Gist options
  • Select an option

  • Save vsitaraman/0988f0aef5745cc82165edf503774b21 to your computer and use it in GitHub Desktop.

Select an option

Save vsitaraman/0988f0aef5745cc82165edf503774b21 to your computer and use it in GitHub Desktop.
Get WordPress Posts: API + Bootstrap 3 Integration (+ Jetpack)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script>
$.getJSON( "{{WORDPRESS URL}}/wp-json/wp/v2/posts", function( data ) {
console.log(data);
var items = [];
var counter = 0;
var clearfix = false;
for (i = 0; i < 3; i++) {
var line = data[i];
var title = line.title.rendered;
var img = line.jetpack_featured_media_url;
var date = moment(line.date).format('MMMM Do, YYYY');
var url = line.link;
var html = `<div class="col-md-4 col-sm-6 col-xs-12">
<a target="_blank" href="`+url+`">
<div class="img-thumb" style="background-image: url('`+img+`');background-size: cover;min-height: 200px;" alt="`+title+`"></div>
</a>
<div class="caption">
<p><span class="date">`+date+`</span></p>
<a target="_blank" href="`+url+`">
<p class="lead">`+title+`</p>
</a>
</div>
</div>`;
items.push(html);
}
$('#press').append( items.join( "" ) )
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment