Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
              <div id="app">

  <div class="container">
    
    <div class="row mb-5">
    
      <div class="col-sm-12">
          
          <h1>WP REST API Search Example (Phase Two)</h1>
        
          <p>Search through six of the most popular WordPress blogs at once, powered by the <a href="https://developer.wordpress.org/rest-api/">WP REST API</a> and <a href="https://vuejs.org/">Vue.JS</a>. This is a companion pen to a tutorial on the <a href="https://www.toptal.com/developers/blog">Toptal Engineering Blog</a>.</p>
        
        <p><a href="https://codepen.io/bacoords/pen/LxjEwz">Return to Phase One</a> | <a href="https://codepen.io/bacoords/pen/qRZNvz">Continue to Final Phase</a></p>
      
      </div>
      
    </div>
  
    <div class="row">
      
      <div class="col-md-4 mb-5 push-md-8">
      
        <div class="sticky-top card">
          
          <div class="card-block">

            <h6>Websites:</h6>

            <div class="form-check" v-for="source in sources">

              <label>

                <input type="checkbox" name="{{source.name}}" v-model="source.on"/>

                {{source.name}}

              </label>  

            </div>
            
          </div>
            
        </div>
      
      </div>
    
      <div class="col-md-8 p-0 pull-md-4">
  
        <div class="container" v-for="source in sources">

          <div class="row">

            <div class="container" v-show="source.on" >

              <div class="row mb-5" v-for="post in source.posts">

                <div class="col-md-12">

                  <h4 v-html='post.title.rendered'></h4>

                  <h5 class="text-muted">Published {{post.date | prettyDate}} on {{source.name}}</h5>
                  
                </div>

                <div class="col-md-12">

                  <div v-html='post.excerpt.rendered'></div>

                  <div class="text-right">

                    <a v-bind:href="post.link" target="_blank">Keep Reading</a>

                  </div>

                </div>

              </div>

            </div>

          </div>

        </div>

      </div>
      
    </div>
    
  </div>

</div>
            
          
!
            
              // Basic body styles
body{
  color: #494949;
  font-family: -apple-system, BlinkMacSystemFont, 
    "Segoe UI", "Roboto", "Oxygen", 
    "Ubuntu", "Cantarell", "Fira Sans", 
    "Droid Sans", "Helvetica Neue", sans-serif !important;
  line-height: 1.4;
  margin-top: 1rem;
}


// Overrides for WordPress.org
.sharedaddy{
  display: none;
}
            
          
!
            
              
var app = new Vue({
  
  el : '#app',
  
  data : function(){
    return {
      sources : [
        {
          name: 'css-tricks.com',
          on: true,
          url : 'https://css-tricks.com/wp-json/wp/v2/posts?per_page=3',
          posts : []
        },
        {
          name: 'poststatus.com',
          on: true,
          url : 'https://poststatus.com/wp-json/wp/v2/posts?per_page=3',
          posts : []
        },
        {
          name: 'torquemag.io',
          on: true,
          url : 'https://torquemag.io/wp-api/wp/v2/posts?per_page=3',
          posts : []
        },
        {
          name: 'wordpress.org',
          on: true,
          url : 'https://wordpress.org/news/wp-json/wp/v2/posts?per_page=3',
          posts : []
        },
        {
          name: 'wpmudev.org',
          on: true,
          url : 'https://premium.wpmudev.org/blog/wp-json/wp/v2/posts?per_page=3',
          posts : []
        },
        {
          name: 'wptavern.com',
          on: true,
          url : 'https://wptavern.com/wp-json/wp/v2/posts?per_page=3',
          posts : []
        }
      ]
    }
  },
  
  filters: {
    
    // Using Moment.js to convert post date to a readable format
    prettyDate: function(value){
      
      // Return if date is empty
      if(!value) return '';
      
      // Convert date to Moment.js
      var date = moment.utc(value);
      
      // Return formatted date
      return date.format("MMM DD, YYYY,");
      
    }
    
  },
  
  methods: {
    
    // Load all posts from separate APIs
    loadPosts : function(){
      
      var self = this;
      
      self.sources.forEach(function(source, index){
        
        self.$delete(source, 'posts');
          
        // Get API with vue-resource     
        self.$http.get(source.url).then(function(response)  {

          self.$set(source, 'posts', response.data);

        }, function(response) {

          console.log('Error');

        });
        
      });
      
    }
    
  },
  
  mounted : function(){
    
    this.$nextTick(function(){

      // Load posts on initial page load
      this.loadPosts();
      
    });
    
  }
  
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console