分类模板分页不工作给出404错误

时间:2016-10-28 10:12:57

标签: wordpress custom-taxonomy

我使用了分类模板texonomy-blog_category.php文件。 但是当我转到第2页时,会出现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();

&GT;

我不知道出了什么问题。请帮助我摆脱困境。 提前致谢

1 个答案:

答案 0 :(得分: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,
                        );