Skip to content

Instantly share code, notes, and snippets.

@woodwardtw woodwardtw/random.html
Last active Nov 28, 2016

Embed
What would you like to do?
single random title and link from WP Rest API
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tom Woodward</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link href='https://fonts.googleapis.com/css?family=Raleway:600,900' rel='stylesheet' type='text/css'>
<style type="text/css">
#thecanvas {
width: 100%;
height: 100%;
margin-top:0;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<div class="underline">
<h4>Blog Posts</h4> <div class="byline">by <a href="http://bionicteaching.com">twwoodward</a></div>
</div>
<script type="text/javascript">
$(document).ready(function(){
console.log("ready"); //just to check in the firebug console.
$.ajax({
url:'https://bionicteaching.com/wp-json/wp/v2/posts/?filter[orderby]=rand&per_page=1',
jsonp:"cb",
dataType:'json',
success: function(data) {
console.log(data);
$('#blog').append('<a href="' + data[0].link + '">' +data[0].title.rendered + '</a>');
} //success
}); //ajax
});//ready
</script>
</div>
<div id="blog"></div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.