Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

Sub-Menu Support #5

Open
killerrin opened this issue Apr 9, 2018 · 3 comments
Open

Sub-Menu Support #5

killerrin opened this issue Apr 9, 2018 · 3 comments

Comments

@killerrin
Copy link

In case anyone wants it, I have managed to modify this nav-walker to support Multi-level submenus.

The submenus are written to fit to this submenu support css/script module: bootstrapthemesco/bootstrap-4-multi-dropdown-navbar.

The steps to support it are just changing a couple lines within the wp-bootstrap-navwalker.php file.

  1. Add these const's to the class
  class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {
    public const BS_MAX_DEPTH = 2;
    public const BS_DROPDOWN_MANUAL_DEPTH = 1;
  1. Replace start_lvl with this
    public function start_lvl( &$output, $depth = 0, $args = array() ) {
      if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
        $t = '';
        $n = '';
      } else {
        $t = "\t";
        $n = "\n";
      }

      if ($depth >= WP_Bootstrap_Navwalker::BS_DROPDOWN_MANUAL_DEPTH) {
        $output         .= $n . str_repeat( $t, $depth ) . '<ul class="dropdown-menu" role="menu">' . $n;
      }
      else {
        $this->dropdown = true;
        $output         .= $n . str_repeat( $t, $depth ) . '<div class="dropdown-menu" role="menu">' . $n;
      }
    }
  1. Replace end_lvl with this
    public function end_lvl( &$output, $depth = 0, $args = array() ) {
      if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
        $t = '';
        $n = '';
      } else {
        $t = "\t";
        $n = "\n";
      }

      if ($depth >= WP_Bootstrap_Navwalker::BS_DROPDOWN_MANUAL_DEPTH) {
        $output         .= $n . str_repeat( $t, $depth ) . '</ul>' . $n;
      }
      else {
        $this->dropdown = false;
        $output         .= $n . str_repeat( $t, $depth ) . '</div>' . $n;
      }
    }
@nathannerdymind
Copy link

nathannerdymind commented Jul 16, 2018

This works great! Thanks

@admhpr
Copy link

admhpr commented Jul 25, 2018

Superb. Thank you!

@lukas78
Copy link

lukas78 commented Feb 20, 2019

Hello, thank you, it works!
Unfortunately, the "li" elements & classes ( menu-item menu-item-object-post current-menu-item active) are missing. I've tried to solve it, but it doesn't work....can you help?
Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants