admin管理员组

文章数量:1333201

I'm a newbie with wordpress theme creation. I want to create a custom category.php file, I've implemented the loop and it will display the last 8 posts. I have some fake posts to test if all works well, but I'm not able to add a pagination to the category template I have created.

How I can implement the pagination?I'm thinking to use an infinite scrll using the wp rest api but any other solution will be appreciated. This is the code I'm using now, the previous link and the next are not displayed

<?php get_header(); ?>
<?php $current_cat = get_queried_object(); ?>
<div class="container mt-5 pt-5">
    <div class="row m-0">
        <div class="col-sm-12 col-md-12 col-lg-12 mt-2 mb-2">
            <p class="text-uppercase font-weight-bold mt-2 mb-2 section-title"><?php echo $current_cat->cat_name; ?></p>
        </div>  
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>        
        <div class="col-sm-12 col-md-3 col-lg-3 h-100 mt-2 mb-2">
            <img class="img-fluid w-100 h-100" src="<?php echo the_post_thumbnail_url(); ?>">
            <a class="h5 mt-2 mb-2" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <small class="text-muted d-block"><?php echo get_the_date('j F Y' ,$post->ID); ?></small>
        </div>
    <?php echo next_posts_link(); // not working?>
    <?php echo previous_posts_link(); // not working?>
<?php endwhile; endif; ?>    
    </div>
</div>

<?php get_footer(); ?>

本文标签: Pagination for custom categories template