3 * Taxonomy API: Walker_CategoryDropdown class
11 * Core class used to create an HTML dropdown list of Categories.
17 class Walker_CategoryDropdown extends Walker {
19 * @see Walker::$tree_type
23 public $tree_type = 'category';
26 * @see Walker::$db_fields
31 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
34 * Start the element output.
36 * @see Walker::start_el()
39 * @param string $output Passed by reference. Used to append additional content.
40 * @param object $category Category data object.
41 * @param int $depth Depth of category. Used for padding.
42 * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
43 * See {@see wp_dropdown_categories()}.
45 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
46 $pad = str_repeat(' ', $depth * 3);
48 /** This filter is documented in wp-includes/category-template.php */
49 $cat_name = apply_filters( 'list_cats', $category->name, $category );
51 if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
52 $value_field = $args['value_field'];
54 $value_field = 'term_id';
57 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\"";
59 // Type-juggling causes false matches, so we force everything to a string.
60 if ( (string) $category->{$value_field} === (string) $args['selected'] )
61 $output .= ' selected="selected"';
63 $output .= $pad.$cat_name;
64 if ( $args['show_count'] )
65 $output .= ' ('. number_format_i18n( $category->count ) .')';
66 $output .= "</option>\n";