2016-10-28 82 views
0

我已經使用分類模板texonomy-blog_category.php文件。 但是當我移動到第2頁時出現404錯誤。 下面是我的代碼分類模板分頁不工作給404錯誤

<?php 

     get_header('newheader'); 

     $tax = get_query_var('taxonomy'); 
     $term = get_query_var('term'); 


     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
     $count_args=array('post_type' => 'blog_post', 
           'tax_query' => array(
           array(
            'taxonomy' => $tax, 
            'field' => 'slug', 
            'terms' => $term, 
           ), 
          ), 
         ); 

     $count_detail=query_posts($count_args); 
     //echo count($count_detail);exit; 
     $posts_per_page = 2;// get_option('posts_per_page'); 
     $max_page=ceil(count($count_detail)/$posts_per_page); 

     //wp_reset_query(); 

     $args = array('post_type' => 'blog_post', 
           'tax_query' => array(
           array(
            'taxonomy' => $tax, 
            'field' => 'slug', 
            'terms' => $term, 
           ), 
          ), 
           'posts_per_page'=>$posts_per_page, 
          'paged' => $paged,'page'=>$paged, 
          'max_num_pages'=>$max_page, 
          ); 



      $post_detail=query_posts($args); 

    ?> 
    <div class="container"> 
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 main-conten"> 

       <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 blog-main"> 

        <ul class="blog_listing"> 
     <?php 
         for($i=0;$i<count($post_detail);$i++) 
         { 
           $postId=$post_detail[$i]->ID; 
           $ttl=get_the_title($postId); 
           $url=$post_detail[$i]->guid; 
           //print_r($post_detail[$i]); 
         ?> 
        <li> 
        <a href="<?php echo $post_detail[$i]->guid; ?>" ><h1><?php echo get_the_title($postId); ?></h1></a> 

        <div class="blog-img"> 
         <a href="<?php echo $post_detail[$i]->guid; ?>" > 
         <?php //$retina = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) ?> 
          <?php echo get_the_post_thumbnail($postId,array(760,331), $attr); ?> 
         </a>  
        </div> 
        <span> 
         <?php echo date('d F , Y',strtotime($post_detail[$i]->post_date)); ?> 
        </span> 
        <p> 
         <?php echo $post_detail[$i]->post_excerpt; ?> 
        </p> 
        <a class="read-more" href="<?php echo $post_detail[$i]->guid; ?>">Read More</a> </li> 
        </li> 
        <?php }?> 
        </ul> 
        <div class="case_blog"> 
        <?php 
        //wp_reset_postdata(); 
          if (function_exists(custom_pagination)) { 
         custom_pagination($max_page,"",$paged); 
        } 
        ?> 
        </div> 

       <?php //$custom_query = $temp; ?> 
       </div> 
       <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 blog_right_list blog-side"> 
        <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar("Blog Sidebar")) : ?> 
        <?php endif; ?> 
       </div> 

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

    <?php get_footer(); 

?>

我不知道是怎麼回事wrong.please幫助我走出了這一點。 在此先感謝

回答

0

從$ args中刪除頁面參數,您的代碼如下所示。

$args = array('post_type' => 'blog_post', 
          'tax_query' => array(
          array(
           'taxonomy' => $tax, 
           'field' => 'slug', 
           'terms' => $term, 
          ), 
         ), 
          'posts_per_page'=>$posts_per_page, 
         'paged' => $paged, 
         'max_num_pages'=>$max_page, 
         ); 
+0

移除了查詢分頁仍然沒有工作 –

+0

HTTP://stackoverflow.com/questions/36362094/wordpress-category-pagination-not-working-anymore/36370322#36370322 ...是指這個環節,我有在這篇文章中給出答案。如果您仍然遇到問題,請嘗試使用簡單的代碼 –