Forums

loop pages AND subpages ordered by menu_order (4 posts)

  1. skarck
    Member
    Posted 2 years ago #

    Hi!

    I'm developing a single-page layout theme and look for a way to loop all pages and subpages in their logical order (by menu_order), e.g. show the first page, then all its child pages, then page 2 and so on...

    the problem is that wp by defalut seems to give subapges the menu_order of 0 what would all subpages appear at the top of the page list. and i dont want users to set this value manually.

    i also tried to loop all parent pages and then check if they have children, but since i need to use query_posts() and there is no "depth" option like in wp_list_pages this didn't worked out.

    anyone out there who could help?

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    This might work:

    <?php
      $pages = get_pages('sort_column=menu_order');
      foreach ($pages as $page) {
      echo '<p>'.$page->post_title.'</p>';
      }
     ?>
  3. skarck
    Member
    Posted 2 years ago #

    thanks, good idea!

    but using your code results in an nested structure of subpages, what i actually dont want to have.
    when i set "hierarchical=0" what is described as an option to print out a "flat" structure it doesn't sort the pages properly. then again all subpages are listed at the top of the list...

    is this how it should work???

  4. skarck
    Member
    Posted 2 years ago #

    sry, found out that i messed up my html markup...

    get_pages() does its job!

Topic Closed

This topic has been closed to new replies.

About this Topic