AnsPress_Category_Widget::widget( $args, $instance )
Description #
Source #
File: addons/free/category/widget.php
public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } $cat_args = array( 'parent' => $instance['parent'], 'number' => $instance['number'], 'hide_empty' => $instance['hide_empty'], 'orderby' => $instance['orderby'], 'order' => $instance['order'], ); $icon_width = ! empty( $instance['icon_width'] ) ? $instance['icon_width'] : 32; $icon_height = ! empty( $instance['icon_height'] ) ? $instance['icon_height'] : 32; $categories = get_terms( 'question_category' , $cat_args ); ?> <ul id="ap-categories-widget" class="ap-cat-wid clearfix"> <?php foreach ( (array) $categories as $key => $category ) : $ap_category = get_term_meta( $category->term_id, 'ap_category', true ); $ap_category = wp_parse_args( $ap_category, [ 'color' => '#333', 'icon' => 'apicon-category' ] ); $sub_cat_count = count(get_term_children( $category->term_id, 'question_category' ) ); ?> <li class="clearfix"> <a class="ap-cat-image" style="height:<?php echo $icon_height; ?>px;width:<?php echo $icon_width; ?>px;background: <?php echo esc_attr( $ap_category['color'] ); ?>" href="<?php echo get_category_link( $category );?>"> <span class="ap-category-icon <?php echo esc_attr( $ap_category['icon'] ); ?>"></span> </a> <a class="ap-cat-wid-title" href="<?php echo get_category_link( $category );?>"> <?php echo $category->name; ?> </a> <div class="ap-cat-count"> <span><?php printf(_n('%d Question', '%d Questions', $category->count, 'anspress-question-answer' ), $category->count ); ?></span> <?php if ( $sub_cat_count > 0 ) : ?> <span><?php printf(__('%d Child', 'anspress-question-answer' ), $sub_cat_count ); ?></span> <?php endif; ?> </div> </li> <?php endforeach; ?> </ul> <?php echo $args['after_widget']; }
Expand full source code Collapse full source code View on GitHub: addons/free/category/widget.php:30
Add your comment