I wanted to know how could i display only the children of a nav menu. ive tried a couple of things like :

if($post->post_type == "page"){
            $postid = $post->ID;
            print_r( get_pages(array("child_of" => $postid)) );

But all i get an empty array.

so what i want is something like this: http://www.isic.org/student-card/the-isic-student-card.html


Here you have the solution

     $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
     $subpages = ($post->post_parent) ? wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') ; 
          if ($children) { ?>
              <li><?php echo $children; ?></li>
          <?php } else { ?>
              <?php echo $subpages; ?>
  <?php } ?>
  <?php wp_reset_query() ?>

I used it to make a menu where the case was something like:

Parent Page: Service A Child: Overview, Features, Service Plan, FAQs, Quotes

And there were different services and each parent has their own child.


This really depends on how the menu is setup, but based on the code in your snippet you are using get_pages() so I assume its setup with pages.

Then you are better off using wp_list_pages() and to get the sub pages you would do something like this.


This will give you a list of items that are children of the current post/page id which it seems you are trying to do.

Here is a good tutorial that will probably help best. It sounds pretty much what you are trying to do, but I am not sure exactly as your question is a little vague.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.