【问题标题】:How to indent sub menu in dropdown select - WordPress如何在下拉选择中缩进子菜单 - WordPress
【发布时间】:2016-05-18 09:19:06
【问题描述】:

我正在开发一个 wordpress 菜单,并试图在我的下拉选择框中将子菜单从其父级缩进。

这是它在我的下拉选择框中的样子:

市区

城市A

城市乙

城市中心

发展

开发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";
    }

}

【问题讨论】:

    标签: wordpress drop-down-menu menu navigation submenu


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-17
      • 2023-04-02
      • 1970-01-01
      • 2020-01-25
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多