Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. function h_dopdown_cat() {
  2. echo preg_replace_callback( '/(<option[^>]*>)((?:&nbsp;)+)/u', function ( $matches ) {
  3. return $matches[1] . str_repeat( '–', strlen( $matches[2] ) / 18 ) . ' ';
  4. }, wp_dropdown_categories( [
  5. 'echo' => 0,
  6. 'depth' => 3,
  7. 'hierarchical' => true
  8. ] ) );
  9. }
  10.  
  11. class My_Walker_CategoryDropdown extends Walker_CategoryDropdown {
  12. public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  13. $pad = str_repeat( '-', $depth );
  14.  
  15. /** This filter is documented in wp-includes/category-template.php */
  16. $cat_name = apply_filters( 'list_cats', $category->name, $category );
  17.  
  18. if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
  19. $value_field = $args['value_field'];
  20. } else {
  21. $value_field = 'term_id';
  22. }
  23.  
  24. $output .= "t<option class="level-$depth" value="" . esc_attr( $category->{$value_field} ) . """;
  25.  
  26. // Type-juggling causes false matches, so we force everything to a string.
  27. if ( (string) $category->{$value_field} === (string) $args['selected'] ) {
  28. $output .= ' selected="selected"';
  29. }
  30. $output .= '>';
  31. $output .= $pad . $cat_name;
  32. if ( $args['show_count'] ) {
  33. $output .= '&nbsp;&nbsp;(' . number_format_i18n( $category->count ) . ')';
  34. }
  35. $output .= "</option>n";
  36. }
  37.  
  38. }
  39.  
  40. wp_dropdown_categories( [
  41. 'depth' => 3,
  42. 'hierarchical' => true,
  43. 'walker' => new My_Walker_CategoryDropdown(),
  44. ] );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement