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

Archive page pagination links redirecting to home page instead of going next page

programmeradmin0浏览0评论

I am displaying 2 posts in archive page with pagination. But my next page pagination link is redirecting to the home page instead of going to next page with containing next 2 posts.

The URL is showing like - / but it is redirecting to the index page.

function.php

function pagination_bar( $custom_query ) {
    $total_pages = $custom_query->max_num_pages;
    $big = 999999999; // need an unlikely integer

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

archive.php

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
  'paged'         => $paged,
  'category_name' => 'works',
  'posts_per_page' => 2
);

$wrk = new WP_Query($args);

while ($wrk->have_posts() ) {
    $wrk->the_post();?>

<a href="<?php the_permalink() ?>">
  <div class="inner_work">
    <div class="work_arc_img">
      <?php the_post_thumbnail(); ?>
    </div>
    <div class="work_card">
      <p class="in_work_title"><?php the_title(); ?></p>
    </div>
  </div>
</a>

<?php }  ?>

<nav class="pagination">
    <?php pagination_bar( $wrk ); ?>
</nav>

<?php wp_reset_postdata();?>
发布评论

评论列表(0)

  1. 暂无评论