Title: Problem with loops
Last modified: August 19, 2016

---

# Problem with loops

 *  [omcfarlane](https://wordpress.org/support/users/omcfarlane/)
 * (@omcfarlane)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/problem-with-loops/)
 * Hi,
 * I’m hoping to get some help with condensing/correcting this code. Basically, 
   what I want to happen is that it queries for the latest child of a category and
   only displays those posts. From there, if a post is say “featured” I want one
   thing to happen vs. say “sub-featured” where something else would happen. However,
   I want it to deal with the featured posts before it does anything to the sub-
   featured posts regardless of the posting order (I’m hoping this makes sense).
   Here’s the code:
 *     ```
       <?php
       			$category = get_categories('child_of=32&amp;order=DESC');
       			$category = array_values($category);
       			query_posts('cat=' . $category[0]->cat_ID);
   
       		?>
       				<?php while ( have_posts() ) : the_post(); $do_not_duplicate = $post->ID;
       					if ( in_category(41) ) {
       					include(TEMPLATEPATH . '/featured.php');
       					} elseif ( in_category(43) ) {
       					include(TEMPLATEPATH . '/sub-features.php');
       					} else {
       					}
       				?>
   
       			<div id="post-<?php the_ID() ?>" class="post">
       				<h3 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?></a></h3>
   
       				<div class="clear"></div>
       			</div><!-- #post -->
   
       		<?php endwhile ?>
       ```
   
 * Any and all help would be greatly appreciated. Thanks in advance.

The topic ‘Problem with loops’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [omcfarlane](https://wordpress.org/support/users/omcfarlane/)
 * Last activity: [17 years, 7 months ago](https://wordpress.org/support/topic/problem-with-loops/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
