keyaspects

functions file

Aug 29th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.49 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  if (function_exists('register_nav_menus')) {
  5.         register_nav_menus(
  6.             array(
  7.                 'left-nav' => __( 'LeftNav' ),
  8.                 'team-level1' => __( 'Team Level 1' ),
  9.                 'team-level2' => __( 'Team Level 2' ),
  10.                 'team-level3' => __( 'Team Level 3' ),
  11.                 'team-level4' => __( 'Team Level 4' ),                                                 
  12.             )
  13.         );
  14.     }
  15.  
  16.  
  17. // activates Featured Image function
  18.     add_theme_support( 'post-thumbnails' );
  19.  
  20.  
  21.  
  22. class Menu_With_Description extends Walker_Nav_Menu {
  23.     function start_el(&$output, $item, $depth, $args) {
  24.         global $wp_query;
  25.        
  26.         $indent = ( $depth ) ? str_repeat( "t", $depth ) : '';
  27.  
  28.         $class_names = $value = '';
  29.  
  30.         $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  31.  
  32.         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  33.         $class_names = ' class="' . esc_attr( $class_names ) . '"';
  34.  
  35.         $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  36.  
  37.         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  38.         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  39.         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  40.         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  41.        
  42.         // get user defined attributes for thumbnail images
  43.         $attr_defaults = array( 'class' => 'nav_thumb' , 'alt' => esc_attr( $item->attr_title ) , 'title' => esc_attr( $item->attr_title ) );
  44.         $attr = isset( $args->thumbnail_attr ) ? $args->thumbnail_attr : '';
  45.         $attr = wp_parse_args( $attr , $attr_defaults );
  46.  
  47.         $item_output = $args->before;
  48.        
  49.         // thumbnail image output
  50.         $item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '<a' . $attributes . '>' : '';
  51.         $item_output .= apply_filters( 'menu_item_thumbnail' , ( isset( $args->thumbnail ) && $args->thumbnail ) ? get_the_post_thumbnail( $item->object_id , ( isset( $args->thumbnail_size ) ) ? $args->thumbnail_size : 'thumbnail' , $attr ) : '' , $item , $args , $depth );      
  52.         $item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '</a>' : '';
  53.        
  54.         // menu link output
  55.         $item_output .= '<a'. $attributes .'>';
  56.         $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  57.        
  58.         // menu description output based on depth
  59.         $item_output .= ( $args->desc_depth >= $depth ) ? '<br /><span class="sub">' . $item->description . '</span>' : '';
  60.        
  61.         // close menu link anchor
  62.         $item_output .= '</a>';
  63.         $item_output .= $args->after;
  64.  
  65.         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  66.     }
  67. }
  68.  
  69.  
  70. add_filter( 'wp_nav_menu_args' , 'my_add_menu_descriptions' );
  71. function my_add_menu_descriptions( $args ) {
  72.     if ( ( $args['theme_location'] == 'team-level1' ) || ( $args['theme_location'] == 'team-level2' ) || ( $args['theme_location'] == 'team-level3' ) || ( $args['theme_location'] == 'team-level4' ) ) {
  73.         $args['walker'] = new Menu_With_Description;
  74.         $args['desc_depth'] = 0;
  75.         $args['thumbnail'] = true;
  76.         $args['thumbnail_link'] = false;
  77.         $args['thumbnail_size'] = 'nav_thumb';
  78.         $args['thumbnail_attr'] = array( 'class' => 'nav_thumb my_thumb' , 'alt' => 'test' , 'title' => 'test' );
  79.     }
  80.  
  81.     return $args;  
  82. }
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment