Is ist possible to render the list elements of the e.g. third level only within the list (ul) that is the active level?
E.g:
– Garden
— Flowers
— Green
— Trees
– Street
– Water
-> Garden/Flowers is active. Street also has childrens but they should not be displayed.
]]>I just updated my site to 4.0 and this plugin stopped working. I have the following code
<?php wp_nav_menu(array(
'depth' => 1,
'level' => 1,
'menu_class' => 'section-header',
'container' => false
)
); ?>
<?php wp_nav_menu(array(
'depth' => 3,
'level' => 2,
'menu_class' => 'sidebar-menu',
'link_before' => '<i class="fa fa-arrow-right"></i>',
)
); ?>
It worked fine before the update. Any ideas how I can get my side navigation back?
Thanks!
]]>Hello,
I came across this plugin and also had problem with 3 level menu (as per other support tickets). It will only display 3rd level menu items for the first 2nd level menu item – even though there are 3rd level items for other 2nd level menu items.
I’ve gone through the code and found the culprit. You don’t need $currentBranch
parameter in level
function.
Here is the level
function that works, without the $currentBranch
parameter and a bit more comments:
/**
* Return a specified level from an indented list of items for a current menu item only.
*
* @since 2.0
*
* @param array $items An intended array of elements (i.e. menu items).
* @param int $level A level of an intended array to start from and return.
* @param int $reached A currently reached level of an intended array.
* @return array An intended array of a current menu item's branch starting at the specified level.
*/
protected function level( $items, $level, $reached = 1 ) {
foreach ( $items as $item ) {
// Check if $item is a current menu item or a current ancestor menu item
if ( $item->current || $item->current_item_ancestor ) {
// Catch top level
if ( 1 === $level && 1 === $reached ) {
return array( $item );
}
// Level is reached - display current item's children if any
if ( $reached + 1 == $level && ! empty( $item->children ) ) {
return $item->children;
}
// Level is not reached - proceed with current item's children if any
if ( ! empty( $item->children ) ) {
return $this->level( $item->children, $level, $reached + 1 );
}
} //end if $item is current or current ancestor
} //end foreach $items
return array();
}
I hope that helps someone. It would be great if one of developers can update the code ??
Many thanks,
Dasha
Seem to be getting the same problem as the last person with a Level 3 problem. I have 3 separate calls to wp_nav_menu for the 3 different levels of navigation the site will have. Need to call this 3 times for the design our guy came up with. Here is an example hierarchy:
When I’m at the top level, everything looks fine. When I am in “Running your organisation” I see the correct second level menu but I also see the 3rd level menu for “Knowledge hub”. In fact it doesn’t matter what 2nd level page in “Running your organisation” I am in, I always see the 3rd level menu for “Knowledge hub”. Even when I am in “Funding” and I would expect to see my 2 temporary child pages.
Here is how I am calling the function:
<?php
wp_nav_menu(
array(
'theme_location'=>'primary',
'level'=>'1',
'depth'=>'1',
'container'=>false
)
);
?>
...
<?php
wp_nav_menu(
array(
'theme_location'=>'primary',
'level'=>'2',
'depth'=>'1',
'container'=>false
)
);
?>
...
<?php
wp_nav_menu(
array(
'theme_location'=>'primary',
'level'=>'3',
'depth'=>'1',
'container'=>false
)
);
?>
Am I doing something wrong here?
Despite all this, props to you for your plugin. New to WordPress theme development and getting my head round making my own Custom Walker didn’t seem fun so your solution looks like the right choice!
Thanks in advance,
Matthew
Hi David,
Thanks for such an useful plugin.
All works wonderful except in a post (single.php)
I’ve tried on Twenty Twelve Theme with:
‘level’ => 1,
‘depth’ => 4,
With a structure like:
–Main Categorie
—-Sub Categorie
——Single Post
And..Nothing happens. If I disable the plugin the menu appears
This make sense?
Thanks
]]>wp_nav_menu(array(‘theme_location’ => ‘primary’,
‘level’ => ‘3’,
‘depth’ => 1));
does not show the correct level 3 menu-items of the current level 2 page.
example:
In a menu structure like:
the result of ‘level’ => ‘3’,’depth’ => 1 is always “Item_A” regardless which Level_2 Item/Page is active. Even the Page on Level 1 shows “Item_A”.
do i miss something ?
]]>Hi there
Loving your Admin Menu plugin, so I’m sure this is something great, too. But how about some screenshots in the repo?
]]>