<ul class="nav__list nav">
<!-- menu__list -->
<li class="nav__item">
<!-- menu__item -->
<a href="" class="nav__link js-active link-width"
>Product #0
<!-- menu__link -->
<span class="js-width"></span>
<!-- button menu__arrow -->
</a>
<span class="nav__arr"></span>
<!-- 00000 -->
<ul class="subnav__list subnav">
<!-- menu__sub-list -->
<li class="subnav__item">
<!-- menu__sub-item -->
<a href="" class="subnav__link">Product #1</a>
<!-- menu__sub-link -->
<ul class="sub2nav__list sub2nav">
<!-- menu__subsub-list -->
<li class="sub2nav__item">
<!-- menu__subsub-item -->
<a href="" class="sub2nav__link">Product #2</a>
<!-- menu__subsub-link -->
</li>
</ul>
</li>
</ul>
</li>
</ul>
<?php
class My_Walker_Nav_Menu extends Walker_Nav_Menu
{
// add classes to ul sub-menus
function start_lvl(&$output, $depth = 0, $args = NULL)
{
// depth dependent classes
$indent = ($depth > 0 ? str_repeat("\t", $depth) : ''); // code indent
$display_depth = ($depth + 1); // because it counts the first submenu as 0
$classes = array(
'',
($display_depth % 2 ? 'menu-odd' : 'menu-even'),
($display_depth >= 2 ? 'sub2nav__list sub2nav' : 'subnav__list subnav'),
'menu-depth-' . $display_depth
);
$class_names = implode(' ', $classes);
// build html
if ($display_depth === 0):
//$output .= "\n" . $indent . '<span" class="nav__arr">' . "</span>"; ????? not work
$output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
else:
$output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
endif;
}
// add main/sub classes to li's and links
function start_el(&$output, $item, $depth = 0, $args = NULL, $id = 0)
{
global $wp_query;
$indent = ($depth > 0 ? str_repeat("\t", $depth) : ''); // code indent
// depth dependent classes
$depth_classes = array(
($depth == 0 ? 'nav__item' : ''),
($depth == 1 ? 'subnav__item' : ''),
($depth >= 2 ? 'sub2nav__item' : ''),
//($depth % 2 ? 'item-odd' : 'item-even'),
//'item-depth-' . $depth
);
$depth_class_names = esc_attr(implode('', $depth_classes));
// passed classes
$classes = empty($item->classes) ? array() : (array) $item->classes;
$class_names = esc_attr(implode(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth)));
// build html
$output .= $indent . '<li class="' . $depth_class_names . '">';
// link attributes
$attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
$attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
$attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
$attributes .= ' class="' . ($depth == 0 ? 'nav__link js-active link-width' : '') . ($depth == 1 ? 'subnav__link' : '') . ($depth
>= 2 ? 'sub2nav__link' : '') . '"';
$attributes .= ($depth == 0) ? '>' . '<span class="js-width"></span></a>' : '</a>';
$item_output = sprintf(
//'%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
'<a%2$s',
$args->before,
$attributes,
$args->link_before,
apply_filters('the_title', $item->title, $item->ID),
$args->link_after,
$args->after
);
// build html
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
}