diff --git a/src/AKSRT/Widgets/CategoriesWidget.php b/src/AKSRT/Widgets/CategoriesWidget.php index 5e412231..62e79ec8 100644 --- a/src/AKSRT/Widgets/CategoriesWidget.php +++ b/src/AKSRT/Widgets/CategoriesWidget.php @@ -1,6 +1,6 @@ esc_html__('以列表形式展示文章分类', 'aksrt'), 'customize_selective_refresh' => true, + 'classname' => 'widget_aksrt_categories', ] ); } @@ -37,6 +38,9 @@ class CategoriesWidget extends \WP_Widget { return array_values(array_unique($ids)); } + /** + * @param array $instance + */ public static function render_html(array $instance): string { $count = max(1, min(50, (int) ($instance['count'] ?? 8))); $orderby = sanitize_key((string) ($instance['orderby'] ?? 'count')); @@ -48,12 +52,14 @@ class CategoriesWidget extends \WP_Widget { $hierarchical = !empty($instance['hierarchical']); $parent = max(0, (int) ($instance['parent'] ?? 0)); $show_count = !isset($instance['show_count']) || !empty($instance['show_count']); + $show_desc = !empty($instance['show_desc']); + $show_thumb = !empty($instance['show_thumb']); $exclude = self::parse_ids_static((string) ($instance['exclude'] ?? '')); $include = self::parse_ids_static((string) ($instance['include'] ?? '')); $term_args = [ 'taxonomy' => 'category', - 'number' => $count, + 'number' => $hierarchical ? 0 : $count, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, @@ -61,6 +67,8 @@ class CategoriesWidget extends \WP_Widget { ]; if ($parent > 0) { $term_args['parent'] = $parent; + } elseif ($hierarchical) { + $term_args['parent'] = 0; } if ($include) { $term_args['include'] = $include; @@ -79,19 +87,88 @@ class CategoriesWidget extends \WP_Widget { } ob_start(); - echo '