Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Last active October 6, 2015 06:20
Show Gist options
  • Save scottopolis/ca075abfd326d28e5efe to your computer and use it in GitHub Desktop.
Save scottopolis/ca075abfd326d28e5efe to your computer and use it in GitHub Desktop.
Simple WP-API Ajax to get posts
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>My App</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
padding: 10px;
}
ul {
list-style-type: none;
}
li {
border-bottom: 1px solid #eee;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<ul id="app"></div>
</body>
<script>
jQuery(document).ready(function($) {
$.get( "http://scottbolinger.com/wp-json/wp/v2/posts", function( data ) {
$.each( data, function( i, val ) {
$( "#app" ).append(
'<li>' +
'<h3>' +
val.title.rendered +
'</h3>' +
'<p>' +
val.excerpt.rendered +
'</p>' +
'</li>'
);
});
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment