向 archive.php 模板添加分页

Add pagination to archive.php template

我已经在我的定制 Wordpress 网站中创建了一个存档模板,但我需要添加分页 - 我尝试了不同的 plugins/code 但似乎没有任何效果。我目前在后端设置了 6 个帖子,但出于测试目的,我将其限制为每页 3 个帖子。现有代码如下:

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

$args = array(
    'post_type'  =>  'post',
    'post_status'       =>  'publish',
    'orderby'   => 'date', 
    'order'     => 'ASC',
    'posts_per_page' => 3,
    'paged' => $paged
  );

$posts_query = new WP_Query($args);

if($posts_query->have_posts()) { ?>

    <div class="index-grid">
        <div class="grid-column">
            <?php while($posts_query->have_posts()) {
                $posts_query->the_post(); ?>
                <div class="related-item">
                    <a href="<?php the_permalink(); ?>">
                        <img src="<?php the_field('header_image'); ?>" />
                        <h3 class="title"><?php the_title(); ?></h3>
                        <p class="blurb"><?php the_field('introduction'); ?></p>
                    </a>
                </div>
            <?php } ?>
        </div>
    </div>

    <?php wp_reset_postdata();
}

?>

</section>```

Any help would be greatly appreciated!

Thanks

试试这个:

<div class='pagination'>
  <?php
    $big = 999999999;
      echo paginate_links( array(
      'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
      'format' => '?paged=%#%',
      'current' => max( 1, get_query_var('paged') ),
      'total' => $posts_query->max_num_pages
    ));
  ?>
<div>