【问题标题】:Issue on Adding A Class to Bootstrap Navbar Walker Dropdown in WP在 WP 中向 Bootstrap Navbar Walker Dropdown 添加类的问题
【发布时间】:2017-10-02 08:07:57
【问题描述】:

使用 Bootstrap 3 和 Navbar Walker 我可以在 Bootstrap 和 WP 模板上创建动态下拉列表,但我还需要将 .dropdown-menu-left 添加到 .dropdown-menu 类中。

如你所见,我通过添加这一行尝试了这个

'dropdown_class'    => 'dropdown-menu dropdown-menu-left',

到原始代码,但显然它无法正常运行。

    <?php
        wp_nav_menu( array(
            'menu'              => 'desktop-main-menu',
            'theme_location'    => 'desktop-main-menu',
            'depth'             => 2,
            'container'         => 'div',
            'container_class'   => 'collapse navbar-collapse',
            'container_id'      => 'desktop-navbar-main-collapse',
            'menu_class'        => 'nav navbar-nav navbar-right',
            'dropdown_class'    => 'dropdown-menu dropdown-menu-left',
            'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
            'walker'            => new WP_Bootstrap_Navwalker())
        );
    ?>

您能告诉我如何添加.dropdown-menu-left ul 吗?

【问题讨论】:

    标签: wordpress-theming wp-nav-walker


    【解决方案1】:

    只需更新 wp-bootstrap-navwalker.php 来自

    public function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat( "\t", $depth );
        $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu \" >\n";
    }
    

    public function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat( "\t", $depth );
        $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu dropdown-menu-left\" >\n";
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多