Title: Loop Order?
Last modified: August 19, 2016

---

# Loop Order?

 *  [acondiff](https://wordpress.org/support/users/acondiff/)
 * (@acondiff)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/)
 * I’ve got a loop here and I was wondering if I can modify this so that the child
   pages show up in a specific order. Right now I think they appear in alphabetical
   order. It doesnt seem to listen to the order numbers that I specify in the wordpress
   admin. Any help would be great. Here is my code:
 *     ```
       <?php $pages = get_pages(array('child_of' => 5)); ?>
           	<?php foreach ($pages as $page): ?>
               <div class="threecol">
               <a href="<?php echo get_permalink($page->ID); ?>">
               <?php echo get_the_post_thumbnail($page->ID, array(250,200)); ?></a>
               <h4><a href="<?php echo get_permalink($page->ID); ?>">
               <?=$page->post_title?></a></h4>
               <p><?=$page->post_content?></p>
               </div>
           	<?php endforeach; ?>
       ```
   
 * Thanks!
    Austin

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371514)
 * Try
 *     ```
       $args = array(
       	'child_of' => 5,
       	'sort_column' => 'menu_order'
       	);
       $pages = get_pages($args);
       ```
   
 * [http://codex.wordpress.org/Function_Reference/get_pages](http://codex.wordpress.org/Function_Reference/get_pages)
 *  Thread Starter [acondiff](https://wordpress.org/support/users/acondiff/)
 * (@acondiff)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371521)
 * thanks alot! that did the trick.
 * one last question. in – $pages = get_pages(array(‘child_of’ => 5)
 * instead of child of the page with an id of 5, how do I get it to detect the current
   pages id and stick it in the place of 5, so that it is loading child pages of
   the page you are currently on? (if that makes any sense at all)
 * thanks again!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371537)
 * Try `$pages = get_pages(array('child_of' => $post->ID)`
 *  Thread Starter [acondiff](https://wordpress.org/support/users/acondiff/)
 * (@acondiff)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371597)
 * ok back to my first question. so if i have any children of children it displays
   them as well (which i dont want them to be displayed). so i tried:
 * ‘max_depth’ => 1,
 * it doesnt work though. any suggestions?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371649)
 * Try
 *     ```
       <?php $args = array(
       	'child_of' => $post->ID,
       	'parent' => $post->ID
       	);
       $pages = get_pages( $args);?>
       ```
   
 *  Thread Starter [acondiff](https://wordpress.org/support/users/acondiff/)
 * (@acondiff)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371715)
 * thats a lot. ok last question i promise. how do you get it to list the children
   of the parent?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371720)
 * There’s an example of just that on the link I gave above.
 *  Thread Starter [acondiff](https://wordpress.org/support/users/acondiff/)
 * (@acondiff)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371729)
 * im sorry but i didn’t find the solution on that page.
 * here is what i wanted to accomplish:
 * in all of the main pages (pages that appear in nav bar) show the children of 
   those pages. then when you get into children of those pages display the children
   of that top parent page. so however deep in the site you are it still displays
   the children of that top page.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371730)
 * That’s a lot more complex. You’ll need to test the current page to see if it 
   has a parent. Then test the parent the same way and so on – back up the tree –
   until you reach a page that doesn’t have a parent. Then you can be sure you’ve
   reached the top level page whose id you can use to display the child pages as
   above.
 * There are a couple of examples in [http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page](http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page)
   Snippets 2 and 4 would seem to provide the best foundation for creating a function
   that you could use to walk back up the page tree.

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

The topic ‘Loop Order?’ is closed to new replies.

## Tags

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

 * 9 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/loop-order/#post-1371730)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
