feat(widgets): number paginate for hot/paid/forum lists

Extend aksrt_get_ajax_number_paginate to HotPosts, PaidPosts, forum
hot/topic lists and product tabs; REST accepts number + paid filters.
This commit is contained in:
kate522 committed 2026-07-21 12:59:05 +08:00
1 parent 22f7e7ecf5
commit 1a92adbaf1
6 files changed
+88 -44

No files matched your search

+18 -10
View File
@@ -141,20 +141,27 @@ class WidgetForumHotTopics extends \WP_Widget {
$max_pages = max(1, (int) $q->max_num_pages);
$total = (int) $q->found_posts;
$has_more = $page < $max_pages;
$base_qs = array_filter([
'count' => $count,
'period' => sanitize_key((string) ($instance['period'] ?? 'week')),
'orderby' => sanitize_key((string) ($instance['orderby'] ?? 'views')),
'style' => $style,
'plate' => max(0, (int) ($instance['plate'] ?? 0)),
'paginate' => $paginate,
], static function ($v) {
return $v !== '' && $v !== null;
});
$rest_base = add_query_arg($base_qs, rest_url('aksrt/v1/widgets/forum-topics'));
$paginate_html = '';
if ($paginate === 'ajax' && $has_more) {
$next = add_query_arg([
'page' => $page + 1,
'count' => $count,
'period' => sanitize_key((string) ($instance['period'] ?? 'week')),
'orderby' => sanitize_key((string) ($instance['orderby'] ?? 'views')),
'style' => $style,
'plate' => max(0, (int) ($instance['plate'] ?? 0)),
'paginate' => 'ajax',
], rest_url('aksrt/v1/widgets/forum-topics'));
$next = add_query_arg(['page' => $page + 1], $rest_base);
$paginate_html = function_exists('aksrt_get_ajax_next_paginate')
? aksrt_get_ajax_next_paginate($total, $page, $count, $next)
: '<div class="text-center theme-pagination ajax-pag"><div class="next-page ajax-next"><a href="' . esc_url($next) . '">' . esc_html__('加载更多', 'aksrt') . '</a></div></div>';
} elseif ($paginate === 'number' && $max_pages > 1) {
$paginate_html = function_exists('aksrt_get_ajax_number_paginate')
? aksrt_get_ajax_number_paginate($total, $page, $count, $rest_base)
: '<div class="ajax-pag hide"><div class="next-page ajax-next"><a href="#"></a></div></div>';
} else {
$paginate_html = '<div class="ajax-pag hide"><div class="next-page ajax-next"><a href="#"></a></div></div>';
}
@@ -231,6 +238,7 @@ class WidgetForumHotTopics extends \WP_Widget {
<label><?php esc_html_e('分页', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('paginate')); ?>">
<option value="ajax" <?php selected(($instance['paginate'] ?? 'ajax'), 'ajax'); ?>><?php esc_html_e('AJAX', 'aksrt'); ?></option>
<option value="number" <?php selected(($instance['paginate'] ?? ''), 'number'); ?>><?php esc_html_e('数字分页', 'aksrt'); ?></option>
<option value="none" <?php selected(($instance['paginate'] ?? ''), 'none'); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
</select>
</label>
@@ -254,7 +262,7 @@ class WidgetForumHotTopics extends \WP_Widget {
'orderby' => $orderby,
'style' => $style,
'plate' => max(0, (int) ($new_instance['plate'] ?? 0)),
'paginate' => sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) === 'none' ? 'none' : 'ajax',
'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) : 'ajax',
];
}
}