feat(widgets): forum hot/recent shared mini rows + rank style
Route hot/recent topics through aksrt_render_forum_topic_mini, add plate filter/orderby/rank badges, and keep ajaxpager payloads consistent.
This commit is contained in:
@@ -15,15 +15,26 @@ class WidgetForumRecentTopics extends \WP_Widget {
|
||||
parent::__construct(
|
||||
'aksrt_forum_recent_topics',
|
||||
__('论坛 - 最新话题', 'aksrt'),
|
||||
['description' => __('显示论坛最新话题列表。', 'aksrt')]
|
||||
[
|
||||
'description' => __('显示论坛最新话题列表(共享迷你行渲染)。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_forum_recent_topics',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
if (!post_type_exists('aksrt_forum_topic')) {
|
||||
return;
|
||||
}
|
||||
$title = !empty($instance['title']) ? $instance['title'] : __('最新话题', 'aksrt');
|
||||
$instance['orderby'] = 'date';
|
||||
$instance['period'] = 'all';
|
||||
$instance['orderby'] = 'date';
|
||||
$instance['period'] = 'all';
|
||||
$instance['style'] = sanitize_key((string) ($instance['style'] ?? 'mini'));
|
||||
if (!in_array($instance['style'], ['mini', 'rank'], true)) {
|
||||
$instance['style'] = 'mini';
|
||||
}
|
||||
$instance['paginate'] = sanitize_key((string) ($instance['paginate'] ?? 'ajax'));
|
||||
$instance['plate'] = max(0, (int) ($instance['plate'] ?? 0));
|
||||
$payload = WidgetForumHotTopics::query_payload($instance, 1);
|
||||
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
@@ -40,7 +51,8 @@ class WidgetForumRecentTopics extends \WP_Widget {
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : __('最新话题', 'aksrt');
|
||||
$count = !empty($instance['count']) ? (int) $instance['count'] : 5;
|
||||
$plate = (int) ($instance['plate'] ?? 0);
|
||||
$plate = (int) ($instance['plate'] ?? 0);
|
||||
$style = !empty($instance['style']) ? $instance['style'] : 'mini';
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题:', 'aksrt'); ?></label>
|
||||
@@ -50,6 +62,19 @@ class WidgetForumRecentTopics extends \WP_Widget {
|
||||
<label for="<?php echo esc_attr($this->get_field_id('count')); ?>"><?php esc_html_e('数量:', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('count')); ?>" name="<?php echo esc_attr($this->get_field_name('count')); ?>" type="number" value="<?php echo esc_attr((string) $count); ?>" min="1" max="20">
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('版块 ID(可选)', 'aksrt'); ?>
|
||||
<input class="tiny-text" type="number" min="0" name="<?php echo esc_attr($this->get_field_name('plate')); ?>" value="<?php echo esc_attr((string) $plate); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('样式', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('style')); ?>">
|
||||
<option value="mini" <?php selected($style, 'mini'); ?>><?php esc_html_e('迷你信息行', 'aksrt'); ?></option>
|
||||
<option value="rank" <?php selected($style, 'rank'); ?>><?php esc_html_e('排行榜', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('分页', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('paginate')); ?>">
|
||||
@@ -62,9 +87,15 @@ class WidgetForumRecentTopics extends \WP_Widget {
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$style = sanitize_key((string) ($new_instance['style'] ?? 'mini'));
|
||||
if (!in_array($style, ['mini', 'rank'], true)) {
|
||||
$style = 'mini';
|
||||
}
|
||||
return [
|
||||
'title' => sanitize_text_field($new_instance['title'] ?? ''),
|
||||
'count' => max(1, min(20, (int) ($new_instance['count'] ?? 5))),
|
||||
'plate' => max(0, (int) ($new_instance['plate'] ?? 0)),
|
||||
'style' => $style,
|
||||
'paginate' => sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) === 'none' ? 'none' : 'ajax',
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user