我的主菜单中有两个不同的子菜单。我不希望我的助行器在两个子菜单上都有相同的输出,因为我要在每个子菜单按钮上实现两个不同的功能。
如何获得两个不同的输出,以便例如<button @click="function1">First Button</button>在第一个子菜单和<button @click="function2">Second Button</button>第二个子菜单上输出?
菜单.php
<?php wp_nav_menu(array(
'menu' => 'Main Navigation',
'container' => false,
'items_wrap' => '<ul class="main-menu">%3$s</ul>',
'walker' => new m2o_walker_nav_menu()
));
函数.php
class m2o_walker_nav_menu extends Walker_Nav_Menu {
public function start_lvl(&$output, $depth = 0, $args = array())
{
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<button>First Button</button><ul class=\"sub-menu\">\n";
}
public function end_lvl( &$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
}
我尝试将条件与$depth. 但它似乎是相同的深度,因此两者的输出将是相同的。有谁知道为什么$depth不能正常工作?