Walker_CategoryDropdown

Core class used to create an HTML dropdown list of Categories.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-walker-category-dropdown.php  
  1. class Walker_CategoryDropdown extends Walker { 
  2.  
  3. /** 
  4. * What the class handles. 
  5. * @since 2.1.0 
  6. * @access private 
  7. * @var string 
  8. * @see Walker::$tree_type 
  9. */ 
  10. public $tree_type = 'category'; 
  11.  
  12. /** 
  13. * Database fields to use. 
  14. * @since 2.1.0 
  15. * @access public 
  16. * @todo Decouple this 
  17. * @var array 
  18. * @see Walker::$db_fields 
  19. */ 
  20. public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); 
  21.  
  22. /** 
  23. * Starts the element output. 
  24. * @since 2.1.0 
  25. * @access public 
  26. * @see Walker::start_el() 
  27. * @param string $output Passed by reference. Used to append additional content. 
  28. * @param object $category Category data object. 
  29. * @param int $depth Depth of category. Used for padding. 
  30. * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist. 
  31. * See wp_dropdown_categories(). 
  32. * @param int $id Optional. ID of the current category. Default 0 (unused). 
  33. */ 
  34. public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { 
  35. $pad = str_repeat(' ', $depth * 3); 
  36.  
  37. /** This filter is documented in wp-includes/category-template.php */ 
  38. $cat_name = apply_filters( 'list_cats', $category->name, $category ); 
  39.  
  40. if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) { 
  41. $value_field = $args['value_field']; 
  42. } else { 
  43. $value_field = 'term_id'; 
  44.  
  45. $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\""; 
  46.  
  47. // Type-juggling causes false matches, so we force everything to a string. 
  48. if ( (string) $category->{$value_field} === (string) $args['selected'] ) 
  49. $output .= ' selected="selected"'; 
  50. $output .= '>'; 
  51. $output .= $pad.$cat_name; 
  52. if ( $args['show_count'] ) 
  53. $output .= '  ('. number_format_i18n( $category->count ) .')'; 
  54. $output .= "</option>\n";