gpt4 book ai didi

php - 更改 wordpress 中的子菜单类

转载 作者:行者123 更新时间:2023-12-02 06:35:44 24 4
gpt4 key购买 nike

在我的主题中使用 wp_nav_menu 时,我想为包含子列表的项目更改 Worpdress 的默认 sub-menu 类(更改为 dropdown 以适应 Foundation 框架)。

我已查看 this post关于该主题,但我似乎无法使其正常运行。

在我插入的 functions.php 文件中:

class My_Sub_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown\">\n";
}
}

在我的 header.php 文件中,我有:

<?php
$defaults = array(
'theme_location' => 'header-nav',
'menu_class' => 'right',
'walker' => new My_Sub_Menu(),
'container' => false
);
wp_nav_menu( $defaults );
?>

但是什么也没发生。我是否误解了在哪里插入代码?

最佳答案

是不是因为你没有为你的class My_Sub_Menu extends Walker_Nav_Menu指定一个end_lvl

class My_Sub_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown\">\n";
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
}

关于php - 更改 wordpress 中的子菜单类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19704082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com