It is necessary to get the following non-standard menu structure:

<ul class="menu full"> <li class="menu_item_l1"> <a href="/page1621.php"><span>Пункт меню 1</span></a> </li> <li class="menu_item_l1 "> <a href="/page4542.php"><span>Пункт меню 2</span></a> <div class="child submenu line"> <div class="child_wrapp"> <a class="" href="/subpage36541.php">Подменю 1</a> <a class="" href="/subpage87871.php">Подменю 2</a> <a class="" href="/subpage54354.php">Подменю 3</a> </div> </div> </li> </ul> 

I know that it is realizable through a walker , but I do not know how.

  • And what did not suit the standard arbitrary menu? Surely you need a diva with missing lists or something? - SeVlad

1 answer 1

1) Experiment with $ depth (we put the class in a separate file, it is desirable to create a daddy and classes)

 class CustomWalkerNavMenu extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); if($depth == 1){ $output .= "\n$indent<div class=\"child submenu line\">\n<div class=\"child_wrapp\">\n"; }else{ $output .= "\n$indent<ul class=\"sub-menu\">\n"; } } function end_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); if($depth == 1){ $output .= "$indent</div>\n</div>\n"; }else{ $output .= "$indent</ul>\n"; } } function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); $class_names = ' class="' . esc_attr( $class_names ) . '"'; $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; if($depth != 1){ $output .= $indent . '<li' . $id . $value . $class_names .'>'; } $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 ) .'"' : ''; $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } function end_el(&$output, $item, $depth = 0, $args = array()) { if($depth != 1){ $output .= "</li>\n"; } } } 

2) In functions.php we include the file

3) In the menu we call

 wp_nav_menu( array( 'theme_location' => 'head_menu', 'walker' => new CustomWalkerNavMenu(), ) );