最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Pagination on archive.php not working?

programmeradmin2浏览0评论

My pagination isn't working for my archive.php, which I'm using as a template for my blog post categories links.

<div class="row">
            <?php $the_query = new WP_Query( array(
                'posts_per_page'=>1,
                'order'=>'DESC',
                'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
            ); ?>

            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                <div class="col-lg-4 col-md-4 col-sm-12 blog-content text-styles">
                    <a class="blog-post-area" href="<?php the_permalink() ?>">
                        <?php if ( has_post_thumbnail() ) { 
                            the_post_thumbnail('main-news-thumbnail-uncropped', array('class' => 'img-fluid post-image'));
                        } ?> 
                        <h3 class="post-title"><?php the_title() ?></h3>
                        <?php the_excerpt() ?>
                        <a class="blog-post" href="<?php the_permalink() ?>">Read More</a>
                    </a><!--End Link-->
                </div><!--End Columns-->
            <?php endwhile; ?>
        </div><!--End Row-->

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="pagination">
                    <?php 
                        $big = 999999999; // need an unlikely integer?>
                        <?php echo paginate_links( array(
                            'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                            'format' => '?paged=%#%',
                            'current' => max( 1, get_query_var('paged') ),
                            'total' => $the_query->max_num_pages
                        ) );
                    ?>
                    <?php wp_reset_postdata();?>
                </div><!--End Pagination-->
            </div><!--End Columns--->
        </div><!--End Row-->

Any ideas? I can't figure it out!

My pagination isn't working for my archive.php, which I'm using as a template for my blog post categories links.

<div class="row">
            <?php $the_query = new WP_Query( array(
                'posts_per_page'=>1,
                'order'=>'DESC',
                'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
            ); ?>

            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                <div class="col-lg-4 col-md-4 col-sm-12 blog-content text-styles">
                    <a class="blog-post-area" href="<?php the_permalink() ?>">
                        <?php if ( has_post_thumbnail() ) { 
                            the_post_thumbnail('main-news-thumbnail-uncropped', array('class' => 'img-fluid post-image'));
                        } ?> 
                        <h3 class="post-title"><?php the_title() ?></h3>
                        <?php the_excerpt() ?>
                        <a class="blog-post" href="<?php the_permalink() ?>">Read More</a>
                    </a><!--End Link-->
                </div><!--End Columns-->
            <?php endwhile; ?>
        </div><!--End Row-->

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="pagination">
                    <?php 
                        $big = 999999999; // need an unlikely integer?>
                        <?php echo paginate_links( array(
                            'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                            'format' => '?paged=%#%',
                            'current' => max( 1, get_query_var('paged') ),
                            'total' => $the_query->max_num_pages
                        ) );
                    ?>
                    <?php wp_reset_postdata();?>
                </div><!--End Pagination-->
            </div><!--End Columns--->
        </div><!--End Row-->

Any ideas? I can't figure it out!

Share Improve this question edited Jun 6, 2019 at 14:47 M.T asked Jun 6, 2019 at 13:40 M.TM.T 351 silver badge5 bronze badges 2
  • What do you mean by "is not working"? Pager not being displayed? Clicking next does what? Have you tried other answers from here or maybe stackoverflow/questions/39471735/…? – norman.lol Commented Jun 7, 2019 at 11:02
  • archive.php should not be using a custom query. Why are you using $the_query = new WP_Query? For the main templates you should just be using have_posts() and the_post() without $the_query->. – Jacob Peattie Commented Jun 7, 2019 at 14:03
Add a comment  | 

1 Answer 1

Reset to default 0

You're calling wp_reset_postdata() twice. Once is before the call to paginate_links().

发布评论

评论列表(0)

  1. 暂无评论