2014-09-30 79 views
-1

我目前通過查詢從數據庫獲取所有帖子。包含的PHP代碼是自定義Wordpress模板的一部分。我正在使用自定義元框:https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPressWordpress自定義查詢分頁。我如何爲此添加分頁?

我需要做些什麼來分頁每6個職位?

  <?php 
      //get_template_part('content', 'page'); 
      echo'<h2 class="section-header-dark">'.get_the_title().'</h2><hr>'; 

       //adjusting the query 
       $args = array(
        'post_type' => 'blog', 
        'posts_per_page' => -1, 
        'orderby' => 'menu_order', 
        'order' => ASC 
       ); 

       // The Query 
       $latest_post = new WP_Query($args); 
       // The Loop 
       if ($latest_post->have_posts()) 
       { 
        while ($latest_post->have_posts()) 
        { 
         $latest_post->the_post(); 

         $desc = wpautop(get_post_meta(get_the_ID(), '_cw_desc', true)); 

         echo'<div class=""><h5 class="">'. get_the_title(). '</h5>'; 
         echo $desc; 
         echo'<h6 class="news_date f_right"><i>'. get_the_date(). '</i></h6>'; 
         echo'</div><hr>'; 

        } 
       } 
       else 
       { 
        // no posts do nothing 
       } 
       wp_reset_postdata(); 
     ?> 

回答

0

您需要設置'posts_per_page' => 6並添加paged參數設置爲查詢。

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array(
    'posts_per_page' => 6, 
    'paged' => $paged 
); 

?> 

訪問http://codex.wordpress.org/Pagination瞭解更多詳情。