0

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:

<?php
 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>
 <ul>
 <?php echo $children; ?>
 </ul>

<?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.

2
  • 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. Commented May 20, 2011 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. Commented Feb 1, 2012 at 20:08

2 Answers 2

1

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.

0

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

http://codex.wordpress.org/Function_Reference/wp_nav_menu

1
  • 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
    Commented May 20, 2011 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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