cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <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>
            
          
!
            
              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;
  
  p { 
    font-size:12px;
    padding-top:0;
    padding-bottom:0px;
  }
}
            
          
!
            
              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
		} );
    
  } );
  
} );
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console