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:
@@ -109,6 +109,9 @@ class WidgetForumTopicLists extends \WP_Widget {
|
||||
$page = max(1, $page);
|
||||
$style = sanitize_key((string) ($instance['style'] ?? 'mini'));
|
||||
$paginate = sanitize_key((string) ($instance['paginate'] ?? 'ajax'));
|
||||
if (!in_array($paginate, ['none', 'ajax', 'number'], true)) {
|
||||
$paginate = 'ajax';
|
||||
}
|
||||
$q = new \WP_Query(self::build_query_args($instance, $page));
|
||||
$html = self::render_items_html($q, $style);
|
||||
if ($html === '' && $page === 1) {
|
||||
@@ -119,22 +122,26 @@ class WidgetForumTopicLists 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' => max(1, min(30, (int) ($instance['count'] ?? 8))),
|
||||
'orderby' => sanitize_key((string) ($instance['orderby'] ?? 'date')),
|
||||
'style' => $style,
|
||||
'plate_id' => (int) ($instance['plate_id'] ?? 0),
|
||||
'paginate' => $paginate,
|
||||
], static function ($v) {
|
||||
return $v !== '' && $v !== null;
|
||||
});
|
||||
$rest_base = add_query_arg($base_qs, rest_url('aksrt/v1/forum/frontend/widgets/topics'));
|
||||
$paginate_html = '';
|
||||
if ($paginate === 'ajax' && $has_more) {
|
||||
$next = add_query_arg(
|
||||
array_filter([
|
||||
'page' => $page + 1,
|
||||
'count' => max(1, min(30, (int) ($instance['count'] ?? 8))),
|
||||
'orderby' => sanitize_key((string) ($instance['orderby'] ?? 'date')),
|
||||
'style' => $style,
|
||||
'plate_id' => (int) ($instance['plate_id'] ?? 0),
|
||||
'paginate' => 'ajax',
|
||||
]),
|
||||
rest_url('aksrt/v1/forum/frontend/widgets/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, max(1, (int) ($instance['count'] ?? 8)), $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, max(1, (int) ($instance['count'] ?? 8)), $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>';
|
||||
}
|
||||
@@ -258,6 +265,7 @@ class WidgetForumTopicLists extends \WP_Widget {
|
||||
<label><?php esc_html_e('分页', 'aksrt'); ?>
|
||||
<select class="widefat" name="<?php echo esc_attr($this->get_field_name('paginate')); ?>">
|
||||
<option value="ajax" <?php selected($instance['paginate'], '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>
|
||||
@@ -273,7 +281,7 @@ class WidgetForumTopicLists extends \WP_Widget {
|
||||
'style' => sanitize_key((string) ($new_instance['style'] ?? 'mini')),
|
||||
'plate_id' => max(0, (int) ($new_instance['plate_id'] ?? 0)),
|
||||
'current_plate' => !empty($new_instance['current_plate']) ? 1 : 0,
|
||||
'paginate' => sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')),
|
||||
'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) : 'ajax',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user