Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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