Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. class Nav_Walker_Nav_Menu extends Walker_Nav_Menu {
  2. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  3. global $wp_query;
  4. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  5.  
  6. $class_names = '';
  7.  
  8. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  9. $classes[] = 'menu-item-' . $item->ID;
  10.  
  11. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  12. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
  13.  
  14. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  15. $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
  16.  
  17. $menu_item_descr = get_field( 'menu_descr', $item->ID );
  18.  
  19. $output .= $indent . '<li' . $id . $class_names .'>';
  20.  
  21. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  22. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  23. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  24. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  25.  
  26. $item_output = $args->before;
  27. $item_output .= '<a'. $attributes .'>';
  28. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  29.  
  30. if ( 'top' == $args->theme_location ) {
  31. $submenus = 0 == $depth || 1 == $depth ? get_posts( array( 'post_type' => 'nav_menu_item', 'numberposts' => 1, 'meta_query' => array( array( 'key' => '_menu_item_menu_item_parent', 'value' => $item->ID, 'fields' => 'ids' ) ) ) ) : false;
  32. $item_output .= ! empty( $submenus ) ? ( 0 == $depth ? ' <i class="fa fa-angle-down" aria-hidden="true"></i>' : ' ' ) : '';
  33. }
  34. $item_output .= '</a>';
  35. $item_output .= ! empty( $menu_item_descr ) ? '<span>'.$menu_item_descr.'</span>' : '';
  36. $item_output .= $args->after;
  37.  
  38. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement