Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <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>
            
          
!

CSS

            
              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;
  }
}
            
          
!

JS

            
              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

Console