I try to add a pagination system on my category.php page.

It works for the first page : for example url/category/cat1/.
Good number of posts is displayed and I get a “read more” link only when it’s needed…

But for the second page : for example url/category/cat1/page/2/. It doesn’t load the code from category.php but from index.php !

What am I missing ?

Code from category.php :

<?php

get_header();

    $categories = get_the_category();

    if ( ! empty( $categories ) ) 
    {
        $category = $categories[0]->name;
    }
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

    query_posts( 'category_name='.$category.'&posts_per_page=1&paged='.$paged );

    while (have_posts()) :

        the_post();
        the_title();
        the_excerpt();

        echo'<a href="'.get_permalink().'"> Read more...</a>';

    endwhile;

    ?>

     <div class="navigation">
     <div class="alignleft"><?php previous_posts_link('&laquo; Previous Entries') ?></div>
     <div class="alignright"><?php next_posts_link('Next Entries &raquo;','') ?></div>
     </div>

     <?php

get_footer();

 ?>

Read more here: WordPress : "Next posts" of a category do not call category.php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: