"api"
Bootstrap 3.0.0 Snippet by evarevirus

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html><html class=''> <head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/aaronrutley/pen/xREVze?q=rest+api&limit=all&type=type-pens" /> <style class="cp-pen-styles">body { background: #f1f1f1; font-family: "Operator Mono"; padding: 10px; } main { background: #FFF; padding: 20px; max-width: 1000px; margin: 0 auto; } a { color: #3498db; text-decoration: none; } a.load-more__button { margin-top: 20px; text-align: center; padding: 10px; background: #222; color: #FFF; display: inline-block; } .post { padding: 20px 0; border-bottom: 1px solid #e5e5e5; } .post p { font-size: 12px; padding-top: 0; padding-bottom: 0px; } </style></head><body> <main> <h1>WP REST API Demo #1</h1> <p>Load latest news from PostStatus.com (<a href="https://poststatus.com/wp-json/wp/v2/posts">https://poststatus.com/wp-json/wp/v2/posts</a> )</p> <ol class="posts"> </ol> <div class="load-more"> <a class="load-more__button" href="#">Load News</a> </div> </main> <script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script >jQuery( function( $ ) { // start fetchpage at 1 var fetchpage = "1"; $('a.load-more__button' ).on( 'click', function ( e ) { // prevent default click event e.preventDefault(); // update the link text $(this).text('Loading posts...'); // ajax call $.ajax( { url: 'https://poststatus.com/wp-json/wp/v2/posts?per_page=5&page=' + fetchpage, success: function ( data, textStatus, request ) { // log all the things // console.log ( data ); // console.log ( textStatus ); // console.log ( request ); // get total number of pages totalpages = request.getResponseHeader('X-WP-TotalPages'); // if current page is less than total pages if(fetchpage <= totalpages) { // for each item $.each( data, function( count, item ) { var title = item.title.rendered; var link = item.link; var excerpt = item.excerpt.rendered; $(".posts").append('<li class="post"><a href="' + link + '" target="_blank">' + title + '</a>'+ excerpt +'</li>'); }); // increment fetchpage fetchpage++; // as long as we still have pages to load if(fetchpage <= totalpages) { $('.load-more a').text('Load More News'); } else { $('.load-more__button').hide(); $('.js-load-more').text('No more news to load.'); } } }, error: function ( data, textStatus, request ) { console.log(data.responseText); }, cache: false } ); } ); } ); //# sourceURL=pen.js </script> </body></html>

Related: See More


Questions / Comments: