kovordaniy
4/29/2016 - 9:32 AM

WP Multi nav walker

WP Multi nav walker

class multi_nav_walker extends Walker_Nav_Menu
{
	// Показывает в начале нового уровня. E.g '<ul>'
	function start_lvl(&$output, $depth=0, $args=array()) {
		switch ($depth) {
			case 0:
				$output .= "<ul class='subnav arrows-list'>";
				break;
		}
	}
	// Показывает в конце нового уровня. E.g '</ul>'
	function end_lvl(&$output, $depth=0, $args=array()) {
		switch ($depth) {
			case 0:
				$output .= "</ul>";
				break;
		}
	}

	function start_el(&$output, $item, $depth, $args)
	{
		global $wp_query, $counter;
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

		$attributes = $item_output = '';

		$href = esc_attr($item->url);

		$attributes .= !empty( $item->url ) ? ' href="' .$href. '"' : '';

		$li_active = ($counter == 0) ? "active" : "";

		switch ($depth) {
			case 0:
				$item_output .= '<li><div class="relative">';
				$item_output .= '<a '. $attributes .'>';
				$item_output .= apply_filters( 'the_title', $item->title, $item->ID );
				$item_output .= '</a>';
				break;
			case 1:
				$item_output .= '<li>';
				$item_output .= '<a '. $attributes .'>';
				$item_output .= apply_filters( 'the_title', $item->title, $item->ID );
				$item_output .= '</a>';
				break;
		}

		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
	}

	function end_el(&$output, $item, $depth, $args) {
		global $counter;
		switch ($depth) {
			case 0:
				$output .= '</div></li>';
				$counter++;
				break;
			case 1:
				$output .= '</li>';
				break;
		}
	}
}