dragunoff

wpquestions.com, ID = 3784

Jan 24th, 2012
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * auto add child terms to nav menus
  5.  */
  6. function custom_walker_nav_menu_start_el ( $item_output, $item, $depth, $args) {
  7.  
  8.     // filter only taxonomy menu items
  9.     if( $item->type == 'taxonomy' ) {
  10.    
  11.         // set args
  12.         $args = array(
  13.             'taxonomy' => $item->object,
  14.             'child_of' => $item->object_id,
  15.             'echo' => 0,
  16.             // 'hide_empty' => 0,
  17.             'show_option_none' => '',
  18.             'title_li' => ''
  19.             );
  20.        
  21.         // check for children
  22.         $children = wp_list_categories( $args );
  23.  
  24.         // if any, append them as a list
  25.         if ( $children )
  26.             $item_output = $item_output . '<ul class="children" >' . $children . '</ul>';
  27.    
  28.     }
  29.    
  30.     return $item_output;
  31.    
  32. }
  33.  
  34. add_filter( 'walker_nav_menu_start_el', 'custom_walker_nav_menu_start_el', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment