I can extend the Walker_Nav_Menu class, but after taking a look to it, it seems there's no way to know when an sub-menu will contain other sub-menu, because there's no data available about its children
You may want to look again mate.
The Walker::display_element(...) method take the "List of elements to continue traversing" (understand children list) as second parameter : array $children_elements
If you do a
var_dump($children_elements);
You will see every entry of your menu.
In order to know if an entry got children, you can check if $children_elements[$id] is empty, with $id beeing the id of the element in question :
$this->has_children = ! empty( $children_elements[ $id ] );
So you could check for each entry of your menu if it has children, and if yes, check if any children have children of his own :
<?php
/**
* menu_walker
*
* @since 1.0.0
* @package My Theme Wordpress
*/
if ( ! class_exists( 'MyThemeWP_Top_Menu_Walker' ) ) {
class MyThemeWP_Top_Menu_Walker extends Walker_Nav_Menu {
/**
* Find menu elements with children containing children and give them the super-parent-class class
* Then call the default display_element method
*/
public function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ){
if ( ! $element ) {
return;
}
$id_field = $this->db_fields['id'];
$id = $element->$id_field;
//var_dump($children_elements[ $id ]); // List the children elements of the element with $id
$this->has_children = ! empty( $children_elements[ $id ] );
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$args[0]['has_children'] = $this->has_children; // Back-compat.
}
// If this element have children
if ( ! empty( $children_elements[$id] ) //&& ( $depth == 0 ) // Remove this comment to apply the super-parent-class only to root elements
//|| $element->category_post != '' && $element->object == 'category'
) {
// var_dump($children_elements[$id]);
// Loop through it's children
foreach ($children_elements[$id] as &$child_element) {
//var_dump($child_element->ID);
//var_dump(! empty( $children_elements[$child_element->ID] ));
// If this child has children of it's own, add super-parent-class to it's parent
if ( ! empty( $children_elements[$child_element->ID] ) ){
$element->classes[] = 'super-parent-class';
}
}
}
// Call default method from virtual parent class
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
} // class MyThemeWP_Top_Menu_Walker END
}
?>
>
selector to only apply big submenu styles to the first level? e.g.ul > li > ul.sub-menu
? Most Menu styling problems can be solved with a little extra CSS knowledge, no need forWalker_Nav_Menu
based solutions