我正在 WordPress 上定制它们。我正在尝试在那里获取子菜单我已通过外观添加子菜单->菜单但子菜单未显示在菜单上
if (has_nav_menu('header-menu')) {
wp_nav_menu([
'theme_location' => 'header-menu',
'container' => '',
'menu_class' => 'navbar-nav ml-auto navlinks',
'fallback_cb' => false,
'depth' => 1,
'walker' => new Guru_Header_Nav_Walker()
]);
}
类 Custom_Header_Nav_Walker()
class Custom_Header_Nav_Walker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = null ) {
$output .= '<ul>';
}
public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
$classes = '';
if( $item->object_id == get_the_ID() ||
( $item->object_id == 543 && is_author() )
) {
$classes .= ' active';
}
$output .= '<li id="id_'.$item->object_id.'" class="nav-item nav-mainlinks '.$classes.'">';
$output .= $args->before;
$output .= '<a class="nav-link" href="'. $item->url .'">';
$output .= $args->link_before . $item->title . $args->link_after;
$output .= '</a>';
$output .= $args->after;
}
public function end_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
$output .= '</li>';
}
public function end_lvl( &$output, $depth = 0, $args = null ) {
$output .= '</ul>';
}
}