• Hi,

    I’m probably missing something here, but I can’t get my post navigation to work right on a custom category page. I want an “archive” page to pull posts from two different categories.

    I have that working using this code:

    <?php
    $my_query = new WP_Query('cat=11,404');
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>

    The page displays posts from categories 11 and 404. At the bottom of the page I’d like to have simple text navigation links to display another set of ten posts from BOTH categories. I am using this code:

    <?php previous_posts_link(__('&laquo; Newer Entries ', TRUE)) ?>
    <?php next_posts_link(__(' Older Entries &raquo;', TRUE)) ?>

    When I test this and click on the Older Entries button it repeats the same list of posts–it doesn’t go on to list any other posts from categories 11 and 404.

    Can anyone tell me if I’m missing something, or if this is just not possible. I’ve spent several hours trying to think of work arounds, and ways to fix this, but I can’t come up with anything.

    Any thoughts would be greatly appreciated! I can provide more information if this is unclear.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter wildcatdigital

    (@wildcatdigital)

    Of course, as soon as I post a question I figure out a work around. This question can be considered “Resolved”.

    I have a similar problem, but my previous or next post links are not displaying at all. Can you tell me what the work around was?

    Could you link the working code you’ve come with?

    I got the same issue using posts_nav_link();

    I can navigate in pages, but it gives me the same pages..

    <!-- The Query -->
     <?php query_posts('posts_per_page=4'); ?>
     <!-- The Loop -->
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
        <!-- The posts -->
     <?php endwhile; endif; ?>
     <?php posts_nav_link('¦', 'Prev', 'Next'); ?>

    There, I’m using “Posts_per_page” to limit the posts for each pages. So when I click on the “Next” link, It should gives me the four nexts.

    Any help?

    your query_posts() is missing the ‘paged’ parameter;

    https://codex.www.ads-software.com/Function_Reference/query_posts#Pagination_Parameters

    integrated into your snippet:
    `<!– The Query –>
    <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; ?>
    <?php query_posts(‘posts_per_page=4&paged=’.$paged); ?>
    <!– The Loop –>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    <!– The posts –>
    <?php endwhile; endif; ?>
    <?php posts_nav_link(‘|’, ‘Prev’, ‘Next’); ?>

    Thx for the reply! I found what you are talking about. It works now

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Next and Previous Links for Two Categories’ is closed to new replies.