如何缩进下拉菜单中的子菜单 select - WordPress

How to indent sub menu in dropdown select - WordPress

我正在处理一个 wordpress 菜单,并试图在我的下拉菜单 select 框中将子菜单缩进远离其父菜单。

这是我的下拉 select 框中的样子:

市区

城市 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";
    }

}

问题已解决。我只是在 start_el 函数

中添加了以下代码
function start_el(&$output, $item, $depth, $args) {
         $item->title = str_repeat("-", $depth * 2) . $item->title;
}