wordpress - 如何在 WordPress 中获取自定义主题的子菜单?
问题描述
我正在 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>';
}
}
解决方案
推荐阅读
- javascript - 对我的 socket.io 服务器的请求中未定义 HTTP 协议版本?
- android - ConstraintLayout - 匹配另一个视图的约束,但添加边距以使其更大
- python - 如何将列表列表转换为字典
- python - 使用 Vispy 为实时信号绘图添加标签
- c++ - 无法检查 QT MYSQL 中是否存在表
- css - 使用 root:将 svg 的填充属性管理为来自 css 变量的 data-uri
- python - 如何在 numba njit 装饰器中指定 dict 类型和 timeit 不重用编译版本
- python - setuptools-scm - 获取最新的标记版本
- python - 使用torch.multiprocessing.spawn时如何修复“无法腌制'_thread.lock'对象”错误
- windows - Octave:隐藏复杂绘图的窗口;改为打印到文件