8000 Sub-Menu Support · Issue #5 · jprieton/wp-bootstrap4-navwalker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.
This repository was archived by the owner on Feb 10, 2020. It is now read-only.
Sub-Menu Support #5
Open
Open
@killerrin

Description

@killerrin

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;
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0