Title: The Loop and subpages
Last modified: August 18, 2016

---

# The Loop and subpages

 *  Resolved [henkblanken](https://wordpress.org/support/users/henkblanken/)
 * (@henkblanken)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/)
 * I want to use The Loop to get not a certain page (you can do that with is_page())
   but a couple of childpages. This is the code, and it’s not working:
 *  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if(
   is_page(‘child_of=7’) ) : ?> <?php the_title(); ?> <?php the_excerpt(); ?> <?
   php else: ?> Sorry <?php endif; ?>
 * <?php endwhile; else: ?>
    <?php _e(‘Sorry, no posts matched your criteria.’);?
   > <?php endif; ?>
 * (PS: 7 is the id of the parent page)
 * Is this not supposed to work? Should I do something less stupid? Thnx

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

 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313017)
 * Nope, that’s not gonna work. Dunno, something like this.
 * `<?php
    $my_pages = &get_pages('child_of=7'); foreach ($my_pages as $page) { 
   setup_postdata($page); the_title(); the_excerpt(); } ?>
 *  Thread Starter [henkblanken](https://wordpress.org/support/users/henkblanken/)
 * (@henkblanken)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313023)
 * Thnx, but no, that doesnt work. It returns as many titles as there are childs.
   So it’s almost working. I’ll have another look.
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313027)
 * _It returns as many titles as there are childs._
    Well, it is supposed to.
 * You may need to rephrase either your observation or your request.
 *  Thread Starter [henkblanken](https://wordpress.org/support/users/henkblanken/)
 * (@henkblanken)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313029)
 * You’re right. Sorry. It returns the same title x times. X being the number of
   childs.
 *  Thread Starter [henkblanken](https://wordpress.org/support/users/henkblanken/)
 * (@henkblanken)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313085)
 * I found the solution here: [http://wordpress.org/support/topic/28770?replies=6](http://wordpress.org/support/topic/28770?replies=6)
 * and it works. Thnx anyway!

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

The topic ‘The Loop and subpages’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [henkblanken](https://wordpress.org/support/users/henkblanken/)
 * Last activity: [20 years, 4 months ago](https://wordpress.org/support/topic/the-loop-and-subpages/#post-313085)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
