Skip to content

Commit 28d6afc

Browse files
committed
updated to the lastest v1.3.1
1 parent 916f523 commit 28d6afc

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

bs5starter/functions/navbar.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,38 @@
22
// bootstrap 5 wp_nav_menu walker
33
class bootstrap_5_wp_nav_menu_walker extends Walker_Nav_menu
44
{
5+
private $current_item;
6+
private $dropdown_menu_alignment_values = [
7+
'dropdown-menu-start',
8+
'dropdown-menu-end',
9+
'dropdown-menu-sm-start',
10+
'dropdown-menu-sm-end',
11+
'dropdown-menu-md-start',
12+
'dropdown-menu-md-end',
13+
'dropdown-menu-lg-start',
14+
'dropdown-menu-lg-end',
15+
'dropdown-menu-xl-start',
16+
'dropdown-menu-xl-end',
17+
'dropdown-menu-xxl-start',
18+
'dropdown-menu-xxl-end'
19+
];
20+
521
function start_lvl(&$output, $depth = 0, $args = array())
622
{
23+
$dropdown_menu_class[] = '';
24+
foreach($this->current_item->classes as $class) {
25+
if(in_array($class, $this->dropdown_menu_alignment_values)) {
26+
$dropdown_menu_class[] = $class;
27+
}
28+
}
729
$indent = str_repeat("\t", $depth);
830
$submenu = ($depth > 0) ? ' sub-menu' : '';
9-
$output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
31+
$output .= "\n$indent<ul class=\"dropdown-menu$submenu " . esc_attr(implode(" ",$dropdown_menu_class)) . " depth_$depth\">\n";
1032
}
1133

1234
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
1335
{
36+
$this->current_item = $item;
1437

1538
$indent = ($depth) ? str_repeat("\t", $depth) : '';
1639

@@ -40,10 +63,11 @@ function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
4063
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
4164

4265
$active_class = ($item->current || $item->current_item_ancestor) ? 'active' : '';
43-
$attributes .= ($args->walker->has_children) ? ' class="nav-link ' . $active_class . ' dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"' : ' class="nav-link ' . $active_class . '"';
66+
$nav_link_class = ( $depth > 0 ) ? 'dropdown-item ' : 'nav-link ';
67+
$attributes .= ( $args->walker->has_children ) ? ' class="'. $nav_link_class . $active_class . ' dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"' : ' class="'. $nav_link_class . $active_class . '"';
4468

4569
$item_output = $args->before;
46-
$item_output .= ($depth > 0) ? '<a class="dropdown-item"' . $attributes . '>' : '<a' . $attributes . '>';
70+
$item_output .= '<a' . $attributes . '>';
4771
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
4872
$item_output .= '</a>';
4973
$item_output .= $args->after;

0 commit comments

Comments
 (0)