Created
June 10, 2016 15:51
-
-
Save joecue/a5f5be917728fceef2d5b9396bc3301d to your computer and use it in GitHub Desktop.
JavaScript from MyCampus - Display Posts from WordPress Via WP REST API
This file contains hidden or 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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script> | |
jQuery(document).ready(function($) { | |
$.getJSON("http://sites.lorainccc.edu/mylccc/wp-json/wp/v2/posts/?filter[category_name]=mycampus", function (data) { | |
$.each(data, function( index ){ | |
var div = $('<div class="post"/>'); | |
div.append( $('<h2 class="announce" />').append(document.createTextNode(data[index].title.rendered)) ); | |
div.append( $(data[index].content.rendered)); | |
$(div).attr('id', data[index].id); | |
$('#announcement-container').append(div); | |
}) | |
}); | |
}); | |
</script> | |
<link href='https://fonts.googleapis.com/css?family=Raleway|Lato' rel='stylesheet' type='text/css'> | |
<style> | |
div.post{ | |
font-family: Raleway; | |
margin: 15px 0 0 5px; | |
border-bottom: solid 1px #9d9d9d; | |
width: 400px; | |
padding: 3px 0; | |
} | |
div.post:last-child{ | |
border: none; | |
} | |
h1.announce{ | |
font-family: Raleway; | |
font-size: 14pt; | |
font-weight: 900; | |
margin: 5px; | |
padding: 0; | |
} | |
div.post h2.announce{ | |
font-size: 12pt; | |
font-weight: 900; | |
margin: 0; | |
padding: 0; | |
} | |
div.post p{ | |
font-family: Lato; | |
font-size: 10pt; | |
color: 9d9d9d; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
<div id="announcement-container"> | |
<h1 class="announce">MyCampus Announcements</h1> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment