I've been looking for a solution to my problem for some time now, and I can't seem to find one.

I have created a submenu using the following code from the Codex:

 if($post->post_parent) {
 $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
 $titlenamer = get_the_title($post->post_parent);

 else {
 $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
 $titlenamer = get_the_title($post->ID);
 if ($children) { ?>

 <h2> <?php echo $titlenamer; ?> </h2>
 <?php echo $children; ?>

<?php } ?>

This worked fine until I added siblings to a child menu.

I want the menu to work like this:

  • Main menu
    • Submenu (Children)
      • Siblings

But using the before code above I get this (as show in this image http://www.inlusiondesign.dk/images/stories/wp_list_pages-problem.png):

  • Main menu
    • Submenu (Children)
    • Siblings

If I where to click e.g. "Test 1" everything is fine again - I suppose this is because it hasn't got any children.

I have tried using "depth=2" in various places, but that didn't work.

Thanks in advance.

  • Wordpress out of the box displays menu the way you want. You just need to do the css to ajdust the display. A simple wp_list_pages will spit out all the pages the way you want them. – Hameedullah Khan May 20 '11 at 5:24
  • Down-voting for being a "drive-by" question. I'll change to an up-vote if the OP comes back to follow up on the question. – Chip Bennett Feb 1 '12 at 20:08

I think you need to use depth=1 rather than depth=2.

You are specifying, via the child_of argument, that you want to display children of the current Page's parent Page. That means that the first level of hierarchy is the current Page (and any of its siblings). The second level of hierarchy would be child pages of the current Page (and of any of the current Page's siblings).

So, give depth=1 a try.


You could try the wp_nav_menu function and create menus in order to get the depth you want.


  • I did actually do that first, but I would like to figure out how the wp_list_pages function works, since its a bit easier on sites with many nested pages. – Anders May 20 '11 at 5:36

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.