'maizzy_category_widget', 'description' => esc_html__('Displays categories and posts.', 'maizzy'), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => esc_html__('Title:', 'maizzy'), 'type' => 'text', 'class' => 'widefat', ), 'top_category' => array( 'label' => esc_html__('Top Categories:', 'maizzy'), 'type' => 'number', 'default' => 5, 'css' => 'max-width:60px;', 'min' => 1, 'max' => 20, ), 'enable_cat_desc' => array( 'label' => esc_html__('Enable Category Description:', 'maizzy'), 'type' => 'checkbox', 'default' => true, ), 'latest_label' => array( 'label' => esc_html__('Latest Label', 'maizzy'), 'type' => 'text', 'default' => esc_html__('Latest:', 'maizzy'), ), ); parent::__construct('maizzy-category-layout', esc_html__('MP: Category Widget', 'maizzy'), $opts, array(), $fields); } /** * Outputs the content for the current widget instance. * * @since 1.0.0 * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. */ function widget( $args, $instance ){ $params = $this->get_params( $instance ); echo $args['before_widget']; if ( !empty( $params['title'] ) ) { echo $args['before_title'] . esc_html( $params['title'] ) . $args['after_title']; } $top_category = $params['top_category']; $enable_cat_desc = $params['enable_cat_desc']; $post_cat_lists = get_categories( array( 'hide_empty' => '0', 'exclude' => '1', ) ); $slug_counts = array(); foreach( $post_cat_lists as $post_cat_list ){ if( $post_cat_list->count >= 1 ){ $slug_counts[] = array( 'count' => $post_cat_list->count, 'slug' => $post_cat_list->slug, 'name' => $post_cat_list->name, 'cat_ID' => $post_cat_list->cat_ID, 'description' => $post_cat_list->category_description, ); } } if( $slug_counts ){ arsort( $slug_counts ); ?>