Skip to content

Instantly share code, notes, and snippets.

@cogdog
Created November 30, 2016 07:16
Show Gist options
  • Save cogdog/8440cef85f27f095af9bd7b8fa970dbc to your computer and use it in GitHub Desktop.
Save cogdog/8440cef85f27f095af9bd7b8fa970dbc to your computer and use it in GitHub Desktop.
Cycle through Random post content from arganee.world fetched by WP 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>Random Arganee</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Raleway:600,900' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function update_wisdom( koans ) {
// update the message div with a random json result array from input
// a posts get query from WP API
//give us a random array item
var wisdom = koans[Math.floor(Math.random()*koans.length)];
$('#msg').html(wisdom.content.rendered);
}
// Let's get some posts!
$.ajax({
url:'http://arganee.world/wp-json/wp/v2/posts/?per_page=25',
jsonp:"cb",
dataType:'json',
success: function(data) {
// save the results in array we can use later
quotes = data;
// go to work!
update_wisdom(quotes);
// update every so often
setInterval(update_wisdom, 5000, quotes);
} //success
}); //ajax
});//ready
</script>
</head>
<body>
<div class="underline">
<h4>Wisdom From Another World</h4>
<div class="byline">by <a href="http://argannee.world">@netnarr</a></div>
</div>
<h4>Say What?</h4>
<div id="msg"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment