I am trying to make my own simple WP theme from scratch and I have run in to some difficulties. Maybe someone can help.

I have a category named "News", whose slug is "news".

The permalink structure in WP is set to:


So, this category is accessible through http://sitename.com/news.

I have made a simple template file named category.php. This is the template code:

<?php get_header(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>   
        <a href="<?php echo get_permalink(); ?>">
            <?php the_title(); ?>
        <?php the_excerpt(); ?> 
        <?php the_date(); ?>
    <?php endwhile; else : ?>
        <?php _e( 'Sorry, no posts matched your criteria.' ); ?>
    <?php endif; ?>
    <?php posts_nav_link( ' · ', 'previous page', 'next page' ); ?>
<?php get_footer(); ?>

I have set the default amount of posts to show per page to 5, in WP's global "Reading settings". When this number is exceeded, a "Next page" pagination link occurs. Okay.

Here is the problem.

This "next page" link links to:


And that URL says: "Sorry, no posts matched your criteria"

Even though there ARE more posts in the category.

What am I missing?

  • The purpose of the %category%/%postname% structure is so that the post permalink starts with the category slug (e.g. cat-1/post-1), but the category permalink still needs the base for paginated requests (e.g. category/cat-1/page/2/). So if you go to category/news and follow the pagination links, you should see the next page is working as expected. – Sally CJ Sep 4 '19 at 1:19
  • Hi Sally, thanks for your answer but I'm afraid it doesn't work. I just tried what you said, but the result is the same. When I go to www.site.com/category/news and click on "next page", it takes me to www.site.com/category/news/page/2 and says - "Sorry, no posts matched your criteria.", even though there ARE more posts in the category. – Tina Malina Sep 5 '19 at 17:49
  • Hi Tina. I'm pretty sure the problem is not with posts_nav_link() because that function actually simply displays the pagination links and it doesn't control the posts query or the page permalink. Try deactivating all plugins and see if the issue persists. You can also switch to any default themes like Twenty Nineteen and then create a child theme having that custom category.php template. I hope that helps. – Sally CJ Sep 7 '19 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.