_POST_Pagination()在wpQuery中不起作用

时间:2021-10-14 作者:user3267302

我正在尝试为自定义wp\\U查询创建分页,下面是我的代码:

<?php
    $btpgid=get_queried_object_id();
    $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;

    $args = array( 
        \'cat\' => 1,
        \'posts_per_page\' => 6, 
        \'paged\' => $paged,
        \'post_type\' => \'post\' 
    );
    $postslist = new WP_Query( $args );

    if ( $postslist->have_posts() ) :
        while ( $postslist->have_posts() ) : $postslist->the_post(); ?>
                                            
                                            
            <div class="col-lg-6 right-padding m-t-50">
                <a href="<?php echo get_permalink(); ?> " title="" class="case-box blog-box" data-aos="flip-left">
                    <span class="green-filter case-image-holder">
                        <?php echo get_the_post_thumbnail(); ?> 
                    </span>
                    <span class="content">
                        <span class="blog-box-title">
                           <?php echo the_title(); ?>
                        </span>
                    </span>
                    <p class="section-p"><?php echo get_the_excerpt(); ?></p>
                </a>
            </div>

        <?php endwhile;  ?>
    <div class="pagination d-flex align-items-center justify-content-center w-100 m-t-50">
        <?php 
            next_posts_link( \'< Starsze posty\', $postslist->max_num_pages );
            previous_posts_link( \'Nowsze posty >\' ); 
            wp_reset_postdata(); ?>
    </div>
<?php endif; ?>
当我只使用“时,一切都很好”;“上一页”;和;“下一步”;站点分页方式如下:

<?php 
    next_posts_link( \'< Starsze posty\', $postslist->max_num_pages );
    previous_posts_link( \'Nowsze posty >\' ); 
    wp_reset_postdata(); 
?>
但当我尝试使用编号分页时,它不会显示任何内容,就像这样:

<?php the_posts_pagination( array(
    \'mid_size\'  => 2,
    \'prev_text\' => __( \'Back\', \'textdomain\' ),
    \'next_text\' => __( \'Onward\', \'textdomain\' ),
) ); ?>
代码中有错误吗?我做错了什么?

1 个回复
SO网友:user3267302

多亏了@Buttered\\u Toast,我成功地通过改变:

<?php the_posts_pagination( array(
    \'mid_size\'  => 2,
    \'prev_text\' => __( \'Back\', \'textdomain\' ),
    \'next_text\' => __( \'Onward\', \'textdomain\' ),
) ); ?>
致:

<?php  echo paginate_links( array(
    \'base\'         => str_replace( 999999999, \'%#%\', esc_url( get_pagenum_link( 999999999 ) ) ),
    \'total\'        => $postslist->max_num_pages,
    \'current\'      => max( 1, get_query_var( \'paged\' ) ),
    \'format\'       => \'?paged=%#%\',
    \'show_all\'     => false,
    \'type\'         => \'plain\',
    \'end_size\'     => 2,
    \'mid_size\'     => 1,
    \'prev_next\'    => true,
    \'prev_text\'    => sprintf(  __( \'<\', \'text-domain\' ) ),
    \'next_text\'    => sprintf(  __( \'>\', \'text-domain\' ) ),
    \'add_args\'     => false,
    \'add_fragment\' => \'\',
    ) );
wp_reset_postdata(); ?>