bdbrown

Most Viewed Posts Page

Mar 18th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Most Viewed Posts Page
  4.  */
  5. ?>
  6.  
  7. <?php get_header(); ?>
  8.  
  9. <section class="content">
  10.  
  11.     <?php get_template_part('inc/page-title'); ?>
  12.    
  13.     <div class="pad group">    
  14.        
  15.         <?php if ((category_description() != '') && !is_paged()) : ?>
  16.             <div class="notebox">
  17.                 <?php echo category_description(); ?>
  18.             </div>
  19.         <?php endif; ?>
  20.        
  21.  
  22.   <?php
  23.  
  24.     // set up our custom query arguments
  25.     $my_query_args = array(
  26.         'meta_key' => 'views',
  27.         'orderby'  => 'meta_value_num',
  28.         'order'    => 'DESC'
  29.     );
  30.  
  31.     // new instance of WP_Query
  32.     $archive_query = new WP_Query( $my_query_args );
  33.  
  34.   ?>
  35.    
  36.         <?php if ( have_posts() ) : ?>
  37.        
  38.             <?php if ( ot_get_option('blog-standard') == 'on' ): ?>
  39.                 <?php while ( $archive_query->have_posts() ): $archive_query->the_post(); ?>
  40.                     <?php get_template_part('content-standard'); ?>
  41.                 <?php endwhile; ?>
  42.             <?php else: ?>
  43.             <div class="post-list group">
  44.                 <?php $i = 1; echo '<div class="post-row">'; while ( $archive_query->have_posts() ): $archive_query->the_post(); ?>
  45.                     <?php get_template_part('content'); ?>
  46.                 <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
  47.             </div><!--/.post-list-->
  48.             <?php endif; ?>
  49.        
  50.             <?php get_template_part('inc/pagination'); ?>
  51.            
  52.         <?php endif; ?>
  53.        
  54.     </div><!--/.pad-->
  55.    
  56. </section><!--/.content-->
  57.  
  58. <?php
  59.     // always reset post data after a custom query
  60.     wp_reset_postdata();
  61. ?>
  62.  
  63. <?php get_sidebar(); ?>
  64.  
  65. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment