2017-02-25 31 views
1

我創建了一個名爲「library」的自定義文章類型及其「文檔」分類;問題出現在分類模板(taxonomy-documentation.php)的分頁中。 我已經確定了每頁「18」個帖子的數量,因爲帖子數量應該是「7」頁面,但是我列出「16」頁面,從「8」到「16」的頁面是空的。 檔案爲分類的網址是:Documentation Archive自定義分類模板中的分頁錯誤

模板循環如下:

 <?php 
     $term = $wp_query->queried_object; 
     $getterm = $term->slug; // get current slug (E.g. winter2015) 
     $args = (array(
     'post_type' => 'library', 
     'showposts' => 18, 
     'paged'=>$paged, 
     'tax_query' => array(
      array(      
       'taxonomy' => 'documentation', 
       'field' => 'slug', 
       'terms' => $getterm 
       ), 
      ), 
     )); 

     $query = new wp_query($args); 
     if ($query -> have_posts()) : while ($query -> have_posts()) : $query -> the_post(); ?> 
      <?php setPostViews(get_the_ID()); ?> 
      <div class="col-md-2"> 
        <?php if (get_post_meta(get_the_ID(), 'download_image', true)) : ?> 
         <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php get_the_title(); ?>"> 
          <?php 
          $postID = $post->ID; 
          $imageURI = get_post_meta($postID, 'download_image', true); 
          $attachmentID = pn_get_attachment_id_from_url ($imageURI); 
          $imagearray = wp_get_attachment_image_src($attachmentID, 'full'); 
          $imageURI = $imagearray[0]; 
          $thumbarray = wp_get_attachment_image_src($attachmentID, 'library-thumbnail'); 
          $thumb_imageURI = $thumbarray[0]; 
          echo "<img class='document-thumbnail' src='". $thumb_imageURI . "' alt='". get_the_title() ."' />"; 
          ?> 
         </a> 
        <?php endif; ?> 
        <a class="document-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?></a><br /> 
        <span><?php echo __('Published by', 'cyberdocentes'); ?> <a class="author-link" href="<?php echo get_author_posts_url(get_the_author_meta('ID'), get_the_author_meta('user_nicename')); ?>"><?php the_author(); ?></a></span> 
      </div> 
     <?php endwhile; rewind_posts(); ?> 
      <div class="clear"></div> 
      <div id="pagination"> 
       <?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> 
       <div class="navigation"> 
        <div class="alignleft"> 
         <?php next_posts_link(__('Next posts','cyberdocentes')); ?> 
        </div> 
        <div class="alignright"> 
         <?php previous_posts_link(__('Previous posts','cyberdocentes')); ?> 
        </div> 
       </div> 
       <?php } ?> 
      </div> 
      <div class="clear"></div> 
     <?php else : ?> 
     <?php endif; ?> 
     <?php flush(); ?> 
+0

解決分頁 – Fliberty

回答

0

解決代碼:

 <div class="documents-list"> 
      <?php 
      $term = get_term_by('slug', get_query_var('term'), get_query_var('documentation')); 
      global $wp_query; 
      query_posts(array_merge($wp_query->query, array('posts_per_page' => 18))); 
      if (have_posts()) : while (have_posts()) : the_post(); ?> 

//CODE OF THE ARTICLES HERE 

      <?php endwhile; rewind_posts(); ?> 
      <?php endif; ?> 
       <div class="clear"></div> 
       <div id="pagination"> 
        <?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> 
        <div class="navigation"> 
         <div class="alignleft"> 
          <?php next_posts_link(__('Next posts','cyberdocentes')); ?> 
         </div> 
         <div class="alignright"> 
          <?php previous_posts_link(__('Previous posts','cyberdocentes')); ?> 
         </div> 
        </div> 
        <?php } ?> 
       </div> 
       <div class="clear"></div> 
      <?php flush(); ?> 
     </div> 
相關問題