Level 3 problem – Solved. Requires plugin code alteration
-
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 inlevel
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
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Level 3 problem – Solved. Requires plugin code alteration’ is closed to new replies.