WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding Child Pages from Menu Listing (7 posts)

  1. rogermeeks
    Member
    Posted 4 years ago #

    I've setup a menu listing using wp_list_pages(). The menu has child pages on two of the menu items. But the client has now asked for the child pages of one of these to be removed from the menu. Is there a way to achieve this using wp_list_pages or should I be using another function. I'd originally removed it using the PageMash plugin but unfortunately it removes it from everywhere and I need the listing to appear on a particular page.

  2. Jonas Grumby
    Member
    Posted 4 years ago #

    You should be able to use the exclude parameter.

    http://codex.wordpress.org/Good_Navigation_Links#Pages

  3. rogermeeks
    Member
    Posted 4 years ago #

    Thanks, sort of works for the moment. But the client will be adding more child pages themselves and they are not going to be able to, know how to or want to edit the function with additional id numbers. Now if there was a parameter that said 'exclude_child_of', then that would be great.

  4. MichaelH
    Member
    Posted 4 years ago #

    Did you see the exclude_tree=x,y,z argument that template tag, wp_list_pages(), provides?

  5. rogermeeks
    Member
    Posted 4 years ago #

    This is no good as it excludes the parent as well as the children. I only want to exclude the children.

  6. MichaelH
    Member
    Posted 4 years ago #

    Will the depth=1 argument work? If not it likely means manually keeping your exclude or include list updated or using Function_Reference/get_pages to determine those child ids you want excluded then use that list with wp_list_pages.

    <?php
    $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' => 'All but children of Parent Page ' . $parent,
        'exclude' =>  implode(",", $pageids)
      );
      wp_list_pages($args);
    }
    ?>
  7. rogermeeks
    Member
    Posted 4 years ago #

    Thanks last solution does the trick. Depth parameter sets for all not just one.

    Many thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags