Support » How-To and Troubleshooting » Display list of child pages plus all parent pages

Display list of child pages plus all parent pages

  • Hello!

    I am having trouble displaying a list of parent pages and child pages. On my front page I want to display all my pages (a list of products), which I simply do with wp_list_pages, but with a few exclusions which I do with exclude.

    Each product is a parent page, but only a few of them have children. When I click on a parent page that has children, I want the children for that page to be displayed, but I still want to display all the other parent pages. Other parent pages with children shall not have their children displayed (probably done with is_page?).

    Also, if I click on a child page, it displays the same list as if I’m visiting a parent page. The page that I’m visiting should also have an “active” css class.

    I suppose this is done using depth and child_of in wp_list_pages, but I just can’t figure it out? Can anyone help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

    No luck there I’m afraid. The only thing I manage to do is display the child pages of a parent page. The sibling parent pages all disappear, which I don’t want them to. This does seem to do the work, but it displays nothing for me, and completely removes the_content() as well.

    // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
    $parent = 93;
      'child_of' => $parent
    $pages = get_pages($args);
    if ($pages) {
      $pageids = array();
      foreach ($pages as $page) {
        $pageids[]= $page->ID;
        'title_li' => 'Tree of Parent Page ' . $parent,
        'include' =>  $parent . ',' . implode(",", $pageids)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display list of child pages plus all parent pages’ is closed to new replies.
Skip to toolbar