KelvinAlf

Icon Menu Walker

Apr 2nd, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // Milton is a Menu Walker
  5. // Yes that's a lame TWD pun
  6.     class Description_Walker extends Walker_Nav_Menu
  7.     {
  8.         /**
  9.          * Start the element output.
  10.          *
  11.          * @param  string $output Passed by reference. Used to append additional content.
  12.          * @param  object $item   Menu item data object.
  13.          * @param  int $depth     Depth of menu item. May be used for padding.
  14.          * @param  array $args    Additional strings.
  15.          * @return void
  16.          */
  17.         function start_el(&$output, $item, $depth, $args)
  18.         {
  19.             $classes     = empty ( $item->classes ) ? array () : (array) $item->classes;
  20.  
  21.             $class_names = join(
  22.                 ' '
  23.             ,   apply_filters(
  24.                     'nav_menu_css_class'
  25.                 ,   array_filter( $classes ), $item
  26.                 )
  27.             );
  28.  
  29.             ! empty ( $class_names )
  30.                 and $class_names = ' class="'. esc_attr( $class_names ) . '"';
  31.  
  32.             $output .= "<li id='menu-item-$item->ID' $class_names>";
  33.  
  34.             $attributes  = '';
  35.  
  36.             ! empty( $item->attr_title )
  37.                 and $attributes .= ' title="'  . esc_attr( $item->attr_title ) .'"';
  38.             ! empty( $item->target )
  39.                 and $attributes .= ' target="' . esc_attr( $item->target     ) .'"';
  40.             ! empty( $item->xfn )
  41.                 and $attributes .= ' rel="'    . esc_attr( $item->xfn        ) .'"';
  42.             ! empty( $item->url )
  43.                 and $attributes .= ' href="'   . esc_attr( $item->url        ) .'"';
  44.  
  45.             // insert description for top level elements only
  46.             // you may change this
  47.             $description = ( ! empty ( $item->description ) and 0 == $depth )
  48.                 ? '<span class="nav_desc">' . esc_attr( $item->description ) . '</span>' : '';
  49.  
  50.             //Insert Icons when added
  51.             $custom = ( ! empty ( $item->custom )and 0 == $depth  )
  52.                 ? '<i class="' . esc_attr( $item->custom ) . '"></i><br><span class="assistive-text">' . esc_attr( $item->attr_title ). '</span>': '';
  53.  
  54.             $title = apply_filters( 'the_title', $item->title, $item->ID );
  55.  
  56.             $item_output = $args->before
  57.                 . "<a $attributes>"
  58.                 . $args->link_before
  59.                 . $custom
  60.                 . '<div class="text"> '
  61.                 . $title
  62.                 . $description
  63.                 . '</div> '
  64.                 . '</a> '
  65.                 . $args->link_after
  66.                 . $args->after;
  67.  
  68.             // Since $output is called by reference we don't need to return anything.
  69.             $output .= apply_filters(
  70.                 'walker_nav_menu_start_el'
  71.             ,   $item_output
  72.             ,   $item
  73.             ,   $depth
  74.             ,   $args
  75.             );
  76.         }
  77.     }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment