Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function h_dopdown_cat() {
- echo preg_replace_callback( '/(<option[^>]*>)((?: )+)/u', function ( $matches ) {
- return $matches[1] . str_repeat( '–', strlen( $matches[2] ) / 18 ) . ' ';
- }, wp_dropdown_categories( [
- 'echo' => 0,
- 'depth' => 3,
- 'hierarchical' => true
- ] ) );
- }
- class My_Walker_CategoryDropdown extends Walker_CategoryDropdown {
- public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
- $pad = str_repeat( '-', $depth );
- /** This filter is documented in wp-includes/category-template.php */
- $cat_name = apply_filters( 'list_cats', $category->name, $category );
- if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
- $value_field = $args['value_field'];
- } else {
- $value_field = 'term_id';
- }
- $output .= "t<option class="level-$depth" value="" . esc_attr( $category->{$value_field} ) . """;
- // Type-juggling causes false matches, so we force everything to a string.
- if ( (string) $category->{$value_field} === (string) $args['selected'] ) {
- $output .= ' selected="selected"';
- }
- $output .= '>';
- $output .= $pad . $cat_name;
- if ( $args['show_count'] ) {
- $output .= ' (' . number_format_i18n( $category->count ) . ')';
- }
- $output .= "</option>n";
- }
- }
- wp_dropdown_categories( [
- 'depth' => 3,
- 'hierarchical' => true,
- 'walker' => new My_Walker_CategoryDropdown(),
- ] );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement