esc_html__('展示论坛话题标签(aksrt_forum_tag)。', 'aksrt'), 'classname' => 'widget_aksrt_forum_topic_terms', ] ); } public function widget($args, $instance): void { $tax = taxonomy_exists('aksrt_forum_tag') ? 'aksrt_forum_tag' : (taxonomy_exists('aksrt_forum_topic_cat') ? 'aksrt_forum_topic_cat' : ''); if ($tax === '') { return; } $number = max(1, min(40, (int) ($instance['number'] ?? 12))); $orderby = sanitize_key((string) ($instance['orderby'] ?? 'count')); $hide_empty = !isset($instance['hide_empty']) || !empty($instance['hide_empty']); $include = $this->parse_ids((string) ($instance['include'] ?? '')); $style = sanitize_key((string) ($instance['style'] ?? 'mini')); $term_args = [ 'taxonomy' => $tax, 'number' => $number, 'hide_empty' => $hide_empty, ]; if ($include) { $term_args['include'] = $include; $term_args['orderby'] = 'include'; } else { if ($orderby === 'name') { $term_args['orderby'] = 'name'; $term_args['order'] = 'ASC'; } elseif ($orderby === 'views') { $term_args['meta_key'] = '_aksrt_views'; $term_args['orderby'] = 'meta_value_num'; $term_args['order'] = 'DESC'; } else { $term_args['orderby'] = 'count'; $term_args['order'] = 'DESC'; } } $terms = get_terms($term_args); if (is_wp_error($terms) || !$terms) { return; } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base); if ($title !== '') { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $list_cls = $style === 'card' ? 'aksrt-ftag-list is-card' : 'aksrt-ftag-list is-mini'; echo '
'; foreach ($terms as $term) { $link = get_term_link($term); if (is_wp_error($link)) { continue; } $icon = (string) get_term_meta($term->term_id, '_aksrt_icon', true); echo ''; if ($icon !== '') { echo ' '; } echo '' . esc_html($term->name) . ''; echo '' . esc_html((string) (int) $term->count) . ''; echo ''; } echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** @return array */ private function parse_ids(string $raw): array { if ($raw === '') { return []; } $ids = []; foreach (preg_split('/[\s,]+/', $raw) ?: [] as $p) { $id = (int) $p; if ($id > 0) { $ids[] = $id; } } return array_values(array_unique($ids)); } public function form($instance): void { ?>

sanitize_text_field((string) ($new_instance['title'] ?? '')), 'number' => max(1, min(40, (int) ($new_instance['number'] ?? 12))), 'orderby' => $orderby, 'style' => ($new_instance['style'] ?? '') === 'card' ? 'card' : 'mini', 'include' => sanitize_text_field((string) ($new_instance['include'] ?? '')), 'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0, ]; } }