__('显示论坛版块列表及话题数量。', 'aksrt')] ); } public static function render_html(array $instance): string { $limit = max(1, min(50, (int) ($instance['count'] ?? $instance['showposts'] ?? 30))); $orderby = sanitize_key((string) ($instance['orderby'] ?? 'menu_order')); $style = sanitize_key((string) ($instance['style'] ?? 'list')); if (!in_array($style, ['list', 'mini'], true)) { $style = 'list'; } // Prefer plate CPT (same as plate_lists lite). if (post_type_exists('aksrt_forum_plate')) { $query_args = [ 'post_type' => 'aksrt_forum_plate', 'post_status' => 'publish', 'posts_per_page' => $limit, 'order' => 'ASC', 'no_found_rows' => true, ]; switch ($orderby) { case 'posts': $query_args['meta_key'] = '_aksrt_posts_count'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'DESC'; break; case 'views': $query_args['meta_key'] = '_aksrt_views'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'DESC'; break; case 'date': $query_args['orderby'] = 'date'; $query_args['order'] = 'DESC'; break; default: $query_args['orderby'] = 'menu_order title'; } $plates = get_posts($query_args); if ($plates) { ob_start(); if ($style === 'mini' && function_exists('aksrt_render_plate_row')) { // Compact mini still uses shared plate row for consistent DOM/lazy. echo '
'; } elseif (function_exists('aksrt_render_plate_row')) { echo ''; } else { echo ''; } return (string) ob_get_clean(); } } // Taxonomy fallback. $term_args = [ 'taxonomy' => 'aksrt_forum_board', 'hide_empty' => !isset($instance['hide_empty']) || !empty($instance['hide_empty']), 'number' => $limit, 'order' => 'ASC', ]; if ($orderby === 'count') { $term_args['orderby'] = 'count'; $term_args['order'] = 'DESC'; } elseif ($orderby === 'name') { $term_args['orderby'] = 'name'; } else { $term_args['orderby'] = 'meta_value_num'; $term_args['meta_key'] = '_aksrt_sort_order'; } $boards = get_terms($term_args); if (is_wp_error($boards) || empty($boards)) { return function_exists('aksrt_get_ajax_null') ? aksrt_get_ajax_null(__('暂无版块', 'aksrt')) : ''; } ob_start(); echo ''; return (string) ob_get_clean(); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); $html = self::render_html($instance); echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } public function form($instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); ?>
sanitize_text_field($new_instance['title'] ?? ''), 'count' => max(1, min(50, (int) ($new_instance['count'] ?? 30))), 'orderby' => $orderby, 'style' => ($new_instance['style'] ?? '') === 'mini' ? 'mini' : 'list', 'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0, ]; } }