Title: multiple loops with if statement syntax question
Last modified: August 18, 2016

---

# multiple loops with if statement syntax question

 *  [rstarr](https://wordpress.org/support/users/rstarr/)
 * (@rstarr)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/)
 * I multiple loops running on one page. The loop I need help with is this:
 * <?php $my_query = new WP_Query(‘category_name=client-list&showposts=1’); ?>
    
   <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php the_content();?
   > <?php endwhile; ?>
 * It works fine. What i want to do, is say “if on specific page, then do a new 
   query for a specific category name. So it’s basically amalgamating the above 
   code with this code:
 * <?php
    if (is_home()) { do the above loop; } ?>
 * And then to make it better, I want to have multiple if statements (for 5 different
   pages that will show a specific category loop). E.g if on “clients” page, make
   a new query for the category “people”, if on “home” page make a new query for“
   news” category. I’m using new query, because there is already a loop for the 
   page content.
 * Anyone good at syntax that can put this together?
 * Thanks!!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496065)
 * Isn’t it simpler to use [Category Templates](http://codex.wordpress.org/Category_Templates)?
   What you described in a complicated way… sounds like what the Cat Template does
   out of the box 🙂
 *  Thread Starter [rstarr](https://wordpress.org/support/users/rstarr/)
 * (@rstarr)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496338)
 * Yes, but i have pages with page content that is called from the main loop in 
   the page (based on page.php). Depending on what page it is, i want a second loop
   in the page to call a specific category loop. So the secondary loop code in the
   page template would say, if this page is A, loop category X, if this page is 
   B, loop category B. so all my code is in one page template.
 * I’m not sure how category templates would work here because i’m not calling a
   category page, rather a page based on page.php
 * does this make sense?
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496343)
 * No, it doesn’t. That’s why it doesn’t work: Pages are not meant to display multiple
   posts.
 *  Thread Starter [rstarr](https://wordpress.org/support/users/rstarr/)
 * (@rstarr)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496345)
 * Ok, how would i write the code just for this:
    If on page A, run this loop:
 * <div id=”pix”>
    <?php $my_query = new WP_Query(‘category_name=pix-1-photos&showposts
   =1’); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <?
   php echo $post->post_content; ?> <?php endwhile; ?> </div>
 *  [colourdreamer](https://wordpress.org/support/users/colourdreamer/)
 * (@colourdreamer)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496510)
 * No answer??

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘multiple loops with if statement syntax question’ is closed to new replies.

## Tags

 * [if](https://wordpress.org/support/topic-tag/if/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 5 replies
 * 3 participants
 * Last reply from: [colourdreamer](https://wordpress.org/support/users/colourdreamer/)
 * Last activity: [19 years, 1 month ago](https://wordpress.org/support/topic/multiple-loops-with-if-statement-syntax-question/#post-496510)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
