Support » Themes and Templates » Sort children by menu order

  • I found this on the wp_list_pages template tag FAQ:

    $children = wp_list_pages('title_li=&child_of=&sort_column=menu_order');
    if ($children) { ?>
    <?php echo $children; ?>
    <?php } ?>

    I modified it to sort by menu_order, which works for any parent pages, but not for the children. Any help is appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • One alternative:

      'orderby' => 'menu_order',
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Pages sorted in menu order';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    wp_reset_query();  // Restore global post data stomped by the_post().

    I need to have the children show up in their own unordered list (with each page in a list under the parent), which is also a list, like this:

    <li>Parent Page</li>
      <li>Child Page</li>
    <li>Another Page (not related to Parent Page)</li>

    Is that possible?

    Not sure. Might look to see if the My Page Order plugin will help you.

    As an update for future readers, the original code I posted above actually does work; set the first child at 1 instead of 0 and it sorts fine.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort children by menu order’ is closed to new replies.