0

I have a structured Custom Menu:

  • parent 1
    • children1_1
    • children1_2
  • parent 2
    • children2_1
    • children2_2
  • parent 3
  • parent 4
    • children4_1

etc.

I want the following: on every page, the parent level items will be shown as main menu.

If a parent level item is active, I want to show the child menu items as a separate list somewhere else in the page.

Is there an "easy" way to achieve this, or do I have to list the menu every time and select the current one with PHP and have headache for this for days? :)

Thanks, cadeyrn

2
  • JQuery and css were made for this.
    – Bainternet
    Commented Apr 19, 2011 at 19:31
  • No thank's, I want it to work without js (opera mini for example), and also SEO-proof. Commented Apr 19, 2011 at 20:11

3 Answers 3

-2

This plugin do exactly what you want!

2
  • Thanks! Although I do not want to put it in a widget, this code really does the dirty work. Commented Aug 22, 2011 at 14:03
  • How does this plugin solve the original question?
    – Tom J Nowell
    Commented Sep 30, 2015 at 19:53
1

This should be fairly simple to execute, using two calls to wp_list_pages(), and appropriate variables.

For the primary (i.e. top-level) navigation menu, simply use the depth argument, e.g.:

wp_list_pages( array(
     // display only top-level hierarchy
     'depth' => 1
) );

This will output a menu of all top-hierarchical-level Pages.

For the secondary (i.e. child-page) navigation menu, simply grab the ID of the current Page, and pass it as the child_of argument. This requires setting a variable to the $post->ID from inside the Loop, so that it is available outside of the Loop.

e.g. inside the Loop:

$parent_page = get_the_ID();

And then outside the Loop, for your child-page navigation menu:

wp_list_pages( array(
     // display all hierarchical levels
     'depth' => 0,
     // only children of the current Page
     'child_of' => $parent_page
) );

The only caveat is that this child-page menu must come after the Loop, or else you will need to make an initial pass through the Loop, find the $post->ID, and then rewind_posts() before the Loop.

1

Can't you just add some CSS code to your style.css something like display: inline-block; (instead of display: none;) to ul.sub-menu for the li.current_page_item?

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.