• I found this on the wp_list_pages template tag FAQ:

    <?php
    $children = wp_list_pages('title_li=&child_of=&sort_column=menu_order');
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?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:

    <?php
    $args=array(
      'orderby' => 'menu_order',
      'order'=>'ASC',
      '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>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter tswartz

    (@tswartz)

    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:

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

    Is that possible?

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

    Thread Starter tswartz

    (@tswartz)

    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.