Walker wp_nav_menu submenu
-
Hello every one
im new in wordpress and i searched a lot how to do a custom menu form wp_nav_menu but i havent found an exemple to do submenu,
so here is my code:
wp_nav_menu(array('container' => false,'menu_id' => 'nav','depth' => 0,'menu_class' => 'sf-menu','walker' => new ik_walker()));
walker functionclass ik_walker extends Walker_Nav_Menu{ function start_lvl(&$output, $depth) { $output .= '<ul id="nav" class="sf-menu">'; } function end_lvl(&$output, $depth) { $output .= '</ul>'; } //add the description to the menu item output function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); $class_names = ' class="' . esc_attr( $class_names ) . '"'; if($item->title == 'Accueil') { $output .= $indent . "<li class='current-menu-item'>"; } else { $output .= $indent . "<li>"; } $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', '<b>' . $item->title . '</b>', $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, $args) { } }
i want to do test if the item if his children then i will change de class of ul to be a sub menu.
- The topic ‘Walker wp_nav_menu submenu’ is closed to new replies.