保持第一个导航栏下拉菜单然后摆脱所有尾随级别的最佳方法是什么?所以我想继续navbar-dropdown悬停在主菜单上,但只列出所有子菜单。
我还想只保留has-dropdown is-hoverable主菜单级别,并在所有子菜单中删除它。
这是我当前的 Navwalker 的样子:
class Navwalker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "<div class='navbar-dropdown'>";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
// Add your custom item classes here
$custom_classes_from_menu = implode(' ', $item->classes); // turn the WP classes object array to string values
$liClasses = 'navbar-item ' . $custom_classes_from_menu; // add the values to your classes list
$hasChildren = $args->walker->has_children;
$liClasses .= $hasChildren? " has-dropdown is-hoverable": "";
if($hasChildren){
$output .= "<div class='".$liClasses."'>";
$output .= "\n<a class='navbar-link' href='".$item->url."'>".$item->title."</a>";
}
else {
$output .= "<a class='".$liClasses."' href='".$item->url."'>".$item->title;
}
// Adds has_children class to the item so end_el can determine if the current element has children
if ( $hasChildren ) {
$item->classes[] = 'has_children';
}
}
public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){
if(in_array("has_children", $item->classes)) {
$output .= "</div>";
}
$output .= "</a>";
}
public function end_lvl (&$output, $depth = 0, $args = array()) {
$output .= "</div>";
}
}
