我正在处理wordpress菜单,并试图在我的下拉复选框中将子菜单缩进它的父菜单。
--这是在我的下拉复选框中的样子:
城市带
城市A
城市B
城市C
开发
发展A
发展B
发展C
我想要的是什么样子:
城市带
-城市A区
-城市B区
-城市C区
开发
-发展A
-发展B
-发展C
这里是我在mobile.php:上下拉的代码
<?php if ( has_nav_menu( 'MobileMainNav' ) ) { ?>
<?php wp_nav_menu( array(
'theme_location' => 'MobileMainNav'
,'walker' => new Walker_Nav_Menu_Dropdown()
,'items_wrap' => '<form><select id="drop-nav" onchange=""><option value="">Select a page ...</option>%3$s</select></form>'
));
}
?>functions.php代码
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
function start_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth);
}
function end_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth);
}
function start_el(&$output, $item, $depth, $args) {
$url = '#' !== $item->url ? $item->url : '';
$output .= '<option value="' . $url . '">' . $item->title;
}
function end_el(&$output, $item, $depth){
$output .= "</option>\n";
}}
发布于 2016-05-19 04:10:42
问题解决了。我只是在start_el函数中添加了以下代码
function start_el(&$output, $item, $depth, $args) {
$item->title = str_repeat("-", $depth * 2) . $item->title;
}https://stackoverflow.com/questions/37295263
复制相似问题