WordPress.org

Ready to get started?Download WordPress

Forums

Nested loops (3 posts)

  1. ziguline
    Member
    Posted 4 years ago #

    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

  2. vtxyzzy
    Member
    Posted 4 years ago #

    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 ?>
  3. ziguline
    Member
    Posted 4 years ago #

    I'll try it out and I'll let you know :D

    thank you so much!

    Dimitri

    ziguline.it

Topic Closed

This topic has been closed to new replies.

About this Topic