• Hi all,

    I am currently fiddling around with the new wp_nav_menu. So far I like it. But I am having troubles building a separate vertical navigation that shows the parents sub-pages only (as definded in the Menu settings in the backend). Is this possible with this new functionality? Or do I still have to use wp_list_pages? This would be quite inconvenient, since I would have to manage another hiearchy in the pages or category settings. I’ve looked around the web for a solution but couldn’t find a fix. I guess v3.0 is yet too new.

    Thanks for a quick note.

    Regards,

    Felix

Viewing 8 replies - 46 through 53 (of 53 total)
  • Of course, the solution would be to hide that child category if you didn’t want it to show, meaning that the current-menu-parent class would still show on the parent.

    Hey there, this walker works great, i just wanted to ask if there is any way you could help me to modify it a bit. I am kind of new and i can’t seem to make this work, i’m trying to get this to work for two days now.

    I want the walker to only show the current submenu, so i have :

    Parent 1
    – Child 1
    – Child 2
    Parent 2
    – Child 3
    – Child 4
    – Child 5
    Parent 3
    – Child 6

    Now if i am on the page Child 1, i see Parent 2’s Childs, and i want it to be like this, when i’m on Parent 1`s childs the menu to show:

    Parent 1
    – Child 1
    – Child 2
    Parent 2
    Parent 3

    When i’m on Parent 2’s childs the menu to show:

    Parent 1
    Parent 2
    – Child 3
    – Child 4
    – Child 5
    Parent 3

    And so on. Is this possible? if it is, could you at least give me a hint or something towards the right way?

    Thank you

    dantdr –
    Sounds like you’re not quite in the right place w/ this thread.
    Try rendering the whole menu with the regular wp_nav_menu function and then hiding what you don’t want to see w/ some CSS.

    ul.sub-menu {display:none;}
    li.current-menu-ancestor ul.sub-menu {display:block;}

    something like that.

    i just managed to do what i needed with the help of danieliser`s function, thanks

    Another subnav walker that seems to work well in a few quick tests:
    https://pastebin.com/Hxnf3WWb

    Found via
    https://wpquestions.com/question/show/id/1522

    Here’s a walker I made to just display child menu items of the current top level one (even if they’re a few deep). Not perfect (it still shows empty

      elements), but thought I’d share in case it helps anyone.

    https://pastebin.com/qJ16h88S

    Ta to everyone on this thread for the posts too!

    Also, the Gecka Submenu (https://www.ads-software.com/extend/plugins/gecka-submenu/) plugin works well.

    Hi all,

    this works for me:

    on wp-includes/classes.php row 860

    change from
    if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) )

    to
    if ( ($max_depth == 0 || $max_depth >= $depth+1 ) && isset( $children_elements[$id]) )

    obviously creating a custom walker duplicating
    the function “display_element” containing the modified code in order to avoid editing the core…

    here it is:

    class Custom_Walker_Nav_Sub_Menu extends Walker_Nav_Menu {
    
    function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    
      if ( !$element )
       return;
    
      $id_field = $this->db_fields['id'];
    
      //display this element
      if ( is_array( $args[0] ) )
       $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
      $cb_args = array_merge( array(&$output, $element, $depth), $args);
      call_user_func_array(array(&$this, 'start_el'), $cb_args);
    
      $id = $element->$id_field;
    
      // descend only when the depth is right and there are childrens for this element
      if ( ($max_depth == 0 || $max_depth >= $depth+1 ) && isset( $children_elements[$id]) ) {
    
       foreach( $children_elements[ $id ] as $child ){
    
        if ( !isset($newlevel) ) {
         $newlevel = true;
         //start the child delimiter
         $cb_args = array_merge( array(&$output, $depth), $args);
         call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
        }
        $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
       }
       unset( $children_elements[ $id ] );
      }
    
      if ( isset($newlevel) && $newlevel ){
       //end the child delimiter
       $cb_args = array_merge( array(&$output, $depth), $args);
       call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
      }
    
      //end this element
      $cb_args = array_merge( array(&$output, $element, $depth), $args);
      call_user_func_array(array(&$this, 'end_el'), $cb_args);
     }
    }
Viewing 8 replies - 46 through 53 (of 53 total)
  • The topic ‘wp_nav_menu: List only 2nd level (separate submenu)?’ is closed to new replies.