• Hi,

    I already have pagination running on a custom loop on my website homepage but can not get it to work for lists of posts in a custom loop in a custom category.php template file.

    I am using the following code:

    <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$my_latest_post = new wp_query( array( 'post_type' => 'post', 'category_name' => $my_category, 'posts_per_page' => 8, 'paged' => $paged ) );
    	while ( $my_latest_post->have_posts() ) : $my_latest_post->the_post();
                     .
                     .
                     .
    	endwhile;
    ?>
    
    <div class="nav-previous alignright"><?php next_posts_link( 'Older Products' ); ?></div>
    
    <div class="nav-next alignleft"><?php previous_posts_link( 'Newer Products' ); ?></div>

    The previous and next post links never display – there is no nav hyperlink present in the browser. The loop itself works fine and I can manipulate all parameters correctly, its just the nav links after it are not displaying.

    Any help much appreciated.

Viewing 1 replies (of 1 total)
  • By default, next_posts_link() looks for the maximum number of pages in $wp_query, set by query_posts(). When you use new WP_Query(), you must pass the number in your query as a parameter, like this:

    // usage with max_num_pages
    next_posts_link( 'Older Entries', $my_latest_post->max_num_pages );
    previous_posts_link( 'Newer Entries' );
Viewing 1 replies (of 1 total)
  • The topic ‘Paginating List Of Posts on Category Page’ is closed to new replies.