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

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

CSS

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

JS

              
                
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

Console