Support » Fixing WordPress » Nested loops

  • Hi,

    I’m trying a solution in order to do the following action:

    1 – I’ve a first query that should display a post with a specific tag

    If there are no post with that specific tag

    2 – run another query in order to display other kind of posts

    Looking at the documentation I didn’t find any solution.. or I’m not able to understand that 🙁

    Thank you for your precious help.

    Dimitri

    ziguline.com

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think you want something like this:

    <?php $counter = 0; ?>
    <?php if (have_posts()) { while (have_posts()) : the_post(); ?>
          <?php ++$counter; ?>
          <!-- do stuff for first loop -->
       <?php endwhile; ?>
    <?php } // End of first loop ?>
    <!-- Do other stuff before second loop -->
    <?php if (!$counter) : ?>
       <?php if (have_posts()) { while (have_posts()) : the_post(); ?>
             <!-- Do stuff for second loop -->
          <?php endwhile; ?>
       <?php } // End of second loop ?>
    <?php endif; // End of if $counter ?>
    Thread Starter ziguline

    (@ziguline)

    I’ll try it out and I’ll let you know 😀

    thank you so much!

    Dimitri

    ziguline.it

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Nested loops’ is closed to new replies.