ThemeShaper Forums » Thematic

[closed]

Does wp_list_pages work on Child pages w/ children?

(1 post)
  • Started 13 years ago by helgatheviking
  • This topic is not resolved
  1. Over at the WP Codex I found a snippet for display a parent page and all its children.

    http://codex.wordpress.org/Template_Tags/wp_list_pages#List_parent_Page_and_all_descendant_Pages

    <?php
    // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    $parent = 93;
    $args=array(
      'child_of' => $parent
    );
    $pages = get_pages($args);
    if ($pages) {
      $pageids = array();
      foreach ($pages as $page) {
        $pageids[]= $page->ID;
      }
    
      $args=array(
        'title_li' => 'Tree of Parent Page ' . $parent,
        'include' =>  $parent . ',' . implode(",", $pageids)
      );
      wp_list_pages($args);
    }
    ?>

    Everything works great if the $parent is a top level page. But if I want to declare a child level page as the parent, and list its children (essentially the grandchildren 3rd level pages)... the function outputs all the correct pages but without the correct hierarchical structure between parent and child.

    If $parent is a child of any other page, I get

    Child 1
    Grandchild 1
    Grandchild 2

    all in the same list. Instead of getting the grandchildren in a sub

      :

      Child 1
      -Grandchild 1
      -Grandchild 2

      This has been driving me nuts, so any help would be appreciated.

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.