__('显示论坛热门话题列表。', 'aksrt')] ); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('热门话题', 'aksrt'); $count = !empty($instance['count']) ? max(1, min(20, (int) $instance['count'])) : 5; $period = !empty($instance['period']) ? sanitize_key($instance['period']) : 'week'; echo $args['before_widget']; echo $args['before_title'] . esc_html($title) . $args['after_title']; $date_query = []; if ($period === 'week') { $date_query = [['after' => '7 days ago']]; } elseif ($period === 'month') { $date_query = [['after' => '30 days ago']]; } $query = new WP_Query([ 'post_type' => 'aksrt_forum_topic', 'posts_per_page' => $count, 'post_status' => 'publish', 'meta_key' => '_aksrt_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'date_query' => $date_query, ]); if ($query->have_posts()) { echo ''; wp_reset_postdata(); } else { echo '

' . esc_html__('暂无话题', 'aksrt') . '

'; } echo $args['after_widget']; } public function form($instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('热门话题', 'aksrt'); $count = !empty($instance['count']) ? (int) $instance['count'] : 5; $period = !empty($instance['period']) ? $instance['period'] : 'week'; ?>

__('显示论坛最新话题列表。', 'aksrt')] ); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('最新话题', 'aksrt'); $count = !empty($instance['count']) ? max(1, min(20, (int) $instance['count'])) : 5; echo $args['before_widget']; echo $args['before_title'] . esc_html($title) . $args['after_title']; $query = new WP_Query([ 'post_type' => 'aksrt_forum_topic', 'posts_per_page' => $count, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', ]); if ($query->have_posts()) { echo ''; wp_reset_postdata(); } else { echo '

' . esc_html__('暂无话题', 'aksrt') . '

'; } echo $args['after_widget']; } public function form($instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('最新话题', 'aksrt'); $count = !empty($instance['count']) ? (int) $instance['count'] : 5; ?>

__('显示论坛版块列表及话题数量。', 'aksrt')] ); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); echo $args['before_widget']; echo $args['before_title'] . esc_html($title) . $args['after_title']; $boards = get_terms([ 'taxonomy' => 'aksrt_forum_board', 'hide_empty' => true, 'orderby' => 'meta_value_num', 'meta_key' => '_aksrt_sort_order', 'order' => 'ASC', ]); if (!is_wp_error($boards) && !empty($boards)) { echo ''; } else { echo '

' . esc_html__('暂无版块', 'aksrt') . '

'; } echo $args['after_widget']; } public function form($instance): void { $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); ?>