• Intro:

    I’ve researched my problem and could not find a solution. In fact, I could not find a similar problem. All the topics I found had to do with splitting up a single loop, so they didn’t really need multiple loops. I need multiple distinct loops.

    I’ve also read the WordPress documentation about multiple loops, but it was not that helpful.

    I’m developing this on my local machine, so I do not have a link to share with you all.

    I have a fair understanding of PHP, but please don’t assume too much, as I’ve only been working with WordPress for about a month or so.

    The problem:

    I’m developing a food blog and I’d like to have a recipe index which contains multiple loops, one for each recipe category (e.g. breakfast, lunch, dinner, etc.). Each loop should only display a limited number of posts within each category, say 5-10 posts, before pagination begins. I’d like each loop to have it’s own separate pagination, if multiple pages exist (more than 5-10 posts) for that category. When a user pages through a particular category, the first set of posts should be replaced by the next set of posts in the loop, but they shouldn’t be taken away from the recipe index page that has the rest of the categories.

    What I’ve got so far:

    <?php
    
      query_posts('category_name=Breakfast&post_status=publish');
      if ( have_posts() ) : while ( have_posts()) : the_post();
    
    ?>
    .
    . HTML stuff
    .
    <?php 
    
      endwhile; endif; 
    
      post_navigation();
    
    ?>
    .
    .
    .
    <?php
    
      query_posts('category_name=Lunch&post_status=publish');
      if ( have_posts() ) : while ( have_posts()) : the_post();
    
    ?>
      .
      . HTML stuff
      .
    
    <?php 
    
      endwhile; endif; 
    
      post_navigation();
    
    ?>

    The function post_navigation() simply echoes the HTML for the pagination. Like so:

    function post_navigation() {
      echo '<div class="navigation">';
      echo '	<div class="next-posts">'.get_next_posts_link('&laquo; OLDER').'</div>';
      echo '	<div class="prev-posts">'.get_previous_posts_link('NEWER &raquo;').'</div>';
      echo '</div>';
    }

    So, I’m able to get my loops to display correctly, but when I try to paginate them, it goes to /recipes/page/2, but the posts don’t change. In fact, the page looks exactly the same as it did before except that both pagination buttons, OLDER and NEWER, display.

    Can someone please advise me on what to try to get this working?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination with Multiple Loops’ is closed to new replies.