更改wordpress中的子菜单类
When using wp_nav_menu
in my theme, I want to change Worpdress' default sub-menu
class for items that contain a child list (to dropdown
to fit for the Foundation framework).
I have reviewed this post on the topic but I cannot seem to get it to function correctly.
In my functions.php
file I have inserted:
class My_Sub_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "
$indent<ul class=\"dropdown\">
";
}
}
And in my header.php
file I have:
<?php
$defaults = array(
'theme_location' => 'header-nav',
'menu_class' => 'right',
'walker' => new My_Sub_Menu(),
'container' => false
);
wp_nav_menu( $defaults );
?>
But nothing occurs. Am I misunderstanding where to insert the code?
在我的主题中使用 我已审核关于该主题的这篇文章但似乎无法使其正常运行 。 p>
在我输入的 在我的 但没有任何事情发生。 我误解了插入代码的位置吗? p>
div> wp_nav_menu code>时,我想更改Worpdress的默认
子菜单 code>类,用于包含子列表的项目(到
下拉列表 code>以适合Foundation框架)。 p>
functions.php code>文件中: p>
class My_Sub_Menu扩展了Walker_Nav_Menu {
function start_lvl(&amp; $ output,$ depth){
$ indent = str_repeat(“\ t”,$ depth);
$ output。=“
$ indent&lt; ul class = \“dropdown \”&gt;
“;
}
}
code> pre>
header.php code>中 我有以下文件: p>
&lt;?php
$ defaults = array(
'themes_location'=&gt;'header- 导航',
'男人 u_class'=&gt; 'right',
'walker'=&gt; new My_Sub_Menu(),
'container'=&gt; false
);
wp_nav_menu($ defaults);
?&gt;
code> pre>
Is it because you haven't specified an end_lvl
for your class My_Sub_Menu extends Walker_Nav_Menu
?
class My_Sub_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "
$indent<ul class=\"dropdown\">
";
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>
";
}
}