Category_Dropdown_Custom_Control

A class to create a dropdown for all categories in your wordpress site.

Defined (1)

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

/lib/customizer/includes/category-dropdown-custom-control.php  
  1. class Category_Dropdown_Custom_Control extends WP_Customize_Control { 
  2. private $cats = false; 
  3.  
  4. public function __construct( $manager, $id, $args = array(), $options = array() ) { 
  5. $this->cats = get_categories($options); 
  6. parent::__construct( $manager, $id, $args ); 
  7.  
  8. /** 
  9. * Render the content of the category dropdown 
  10. * @return HTML 
  11. */ 
  12. public function render_content() { 
  13. if ( ! empty( $this->cats ) ) { 
  14. ?> 
  15. <label> 
  16. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> 
  17. <span class="description customize-control-description"><?php echo esc_attr( $this->description ); ?></span> 
  18. <select <?php $this->link(); ?>> 
  19. <?php 
  20. foreach ( $this->cats as $cat ) { 
  21. printf('<option value="%s" %s>%s</option>', $cat->term_id, selected( $this->value(), $cat->term_id, false ), $cat->name ); 
  22. ?> 
  23. </select> 
  24. </label> 
  25. <?php