在Wordpress中为文章分类页面进行分页


Paginate a category page of posts in Wordpress

是否可以将下一个和以前的帖子链接添加到一个页面,该页面从一个类别查询帖子并显示每个页面的该类别的一个帖子?

这是我目前拥有的:

        <?php query_posts('cat=2&posts_per_page=1'); ?>
        <?php if (have_posts()): while (have_posts()) : the_post(); ?>
            <!-- article -->
            <article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <div class="inner">
                    <div class="gallery" style="background-image: url(<?php the_field('image'); ?>);">
                        <div class="close" data-home="<?php echo home_url(); ?>">
                            <span class="oi" data-glyph="x"></span>
                        </div>
                    </div>
                    <div class="copy">
                        <h2><?php the_title(); ?></h2>
                        <?php the_field('news_content'); ?>
                        <a href="**NEXT_POST_IN_SAME_CATEGORY**">Next</a>
                    </div>
                </div>
            </article>
            <!-- /article -->
        <?php endwhile; ?>

您可以尝试使用next_post_link()

 <?php next_posts_link(); ?>

这似乎是我唯一的解决方案,如果有人需要一个模板:

<?php get_header(); ?>
    <main role="main">
    <!-- section -->
    <section>
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
        <!-- article -->
        <article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <div class="inner">
                <div class="copy">
                    <h2><?php the_title(); ?></h2>
                    <?php the_field('news_content'); ?>
                    <?php the_field('copy'); ?>
                    <br>
                    <br>
                    <?php next_post_link( '%link', 'Next', TRUE, 'post_format' ); ?>  |  <?php previous_post_link( '%link', 'Previous', TRUE, 'post_format' ); ?>
                </div>
            </div>
        </article>
        <!-- /article -->
    <?php endwhile; ?>
    <?php else: ?>
        <!-- article -->
        <article>
            <h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
        </article>
        <!-- /article -->
    <?php endif; ?>
    </section>
    <!-- /section -->
    </main>
<?php get_footer(); ?>