Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

By using the below class, I was able to extend the Walker_Nav_Menu and display the description under the link.

I'm working with an UI that requires to have submenu split that also display the description undeneath.

Can somebody help with this?

class deMaster_Walker extends Walker_Nav_Menu
{
  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 ) . '"';

       $output .= $indent . '<li id="menu-item-'. $item->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        ) .'"' : '';

       $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';

       if($depth != 0)
       {
                 $description = $append = $prepend = "";
       }

        $item_output = $args->before;
        $item_output .= '<a'. $attributes .'>';
        $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
        $item_output .= $description.$args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
        }
}
share|improve this question
2  
What is the question? It sounds like you are asking for help doing what you say you've already done. What works about this and what doesn't? –  s_ha_dum Jun 21 '13 at 13:32
    
Let me explain myself better. I have two menu one on the left hand side, another one in the inner pages. I made this for the left hand side column menu. What I need now is the same but to create a submenu only for inner pages that display a menu containing only the pages link and description for that section. Somehow looks like I don't get how to access only the siblings. –  user1341765 Jun 21 '13 at 15:12
1  
So you want to output only some subtree of this menu? Am I right? –  Krzysiek Dróżdż Jun 21 '13 at 20:04
    
yes you're right –  user1341765 Jun 22 '13 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.