feat(widgets): number paginate + main/tab query depth

Add shared aksrt_get_ajax_number_paginate, MainPosts topics/pay_type/
favorites filters and number pager, TabPosts style/paginate/skeleton
payload, REST wiring, product number AJAX parity.
This commit is contained in:
kate522 committed 2026-07-21 12:16:57 +08:00
1 parent fd65f63170
commit ea3c987695
6 files changed
+373 -61

No files matched your search

+34 -5
View File
@@ -61,11 +61,13 @@ class WidgetAjax {
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
'cat' => max(0, (int) ($request->get_param('cat') ?? 0)),
'limit_day' => max(0, (int) ($request->get_param('limit_day') ?? 0)),
'topics' => sanitize_text_field((string) ($request->get_param('topics') ?? '')),
'pay_type' => sanitize_key((string) ($request->get_param('pay_type') ?? '')),
'style' => sanitize_key((string) ($request->get_param('style') ?? 'list')),
'show_thumb' => $request->get_param('show_thumb') === null ? 1 : (int) $request->get_param('show_thumb'),
'show_meta' => $request->get_param('show_meta') === null ? 1 : (int) $request->get_param('show_meta'),
'show_number' => (int) ($request->get_param('show_number') ?? 0),
'paginate' => sanitize_key((string) ($request->get_param('paginate') ?? 'ajax')),
'paginate' => in_array(sanitize_key((string) ($request->get_param('paginate') ?? 'ajax')), ['none','ajax','number'], true) ? sanitize_key((string) ($request->get_param('paginate') ?? 'ajax')) : 'ajax',
];
$page = max(1, (int) ($request->get_param('page') ?? $request->get_param('paged') ?? 1));
return $this->payload(\AKSRT\Widgets\WidgetMainPosts::query_payload($instance, $page), $page);
@@ -76,6 +78,15 @@ class WidgetAjax {
return $this->fail();
}
$default_count = max(1, min(20, (int) ($request->get_param('count') ?? 5)));
$style = sanitize_key((string) ($request->get_param('style') ?? 'mini'));
if (!in_array($style, ['list', 'card', 'mini'], true)) {
$style = 'mini';
}
$paginate = sanitize_key((string) ($request->get_param('paginate') ?? 'none'));
if (!in_array($paginate, ['none', 'ajax', 'number'], true)) {
$paginate = 'none';
}
$page = max(1, (int) ($request->get_param('page') ?? 1));
$tab = [
'title' => '',
'category_id' => max(0, (int) ($request->get_param('cat') ?? $request->get_param('category_id') ?? 0)),
@@ -83,15 +94,31 @@ class WidgetAjax {
'count' => max(0, min(20, (int) ($request->get_param('tab_count') ?? 0))),
'enabled' => true,
];
$html = \AKSRT\Widgets\TabPostsWidget::render_tab_html($tab, $default_count);
$opts = [
'style' => $style,
'paginate' => $paginate,
'show_thumb' => $request->get_param('show_thumb') === null ? 1 : (int) $request->get_param('show_thumb'),
'show_meta' => $request->get_param('show_meta') === null ? 1 : (int) $request->get_param('show_meta'),
'show_number' => (int) ($request->get_param('show_number') ?? 0),
];
$payload = \AKSRT\Widgets\TabPostsWidget::render_tab_payload($tab, $default_count, $opts, $page);
$html = (string) ($payload['html'] ?? '');
if ($html === '') {
$html = function_exists('aksrt_get_ajax_null')
? aksrt_get_ajax_null(__('暂无文章', 'aksrt'))
: '<p class="widget-empty ajax-item">' . esc_html__('暂无文章', 'aksrt') . '</p>';
} else {
$html = '<div class="widget-tab-posts__list widget-tab-posts__list--mini aksrt-main-posts style-mini">' . $html . '</div>';
$html = '<div class="widget-tab-posts__list widget-tab-posts__list--' . esc_attr($style) . ' aksrt-main-posts style-' . esc_attr($style) . '">' . $html . '</div>';
}
return new \WP_REST_Response(['success' => true, 'html' => $html], 200);
return new \WP_REST_Response([
'success' => true,
'html' => $html,
'paginate_html' => (string) ($payload['paginate_html'] ?? ''),
'has_more' => !empty($payload['has_more']),
'page' => (int) ($payload['page'] ?? $page),
'max_pages' => (int) ($payload['max_pages'] ?? 1),
'total' => (int) ($payload['total'] ?? 0),
], 200);
}
public function rest_paid_posts(\WP_REST_Request $request) {
@@ -181,6 +208,8 @@ class WidgetAjax {
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
'cat' => max(0, (int) ($request->get_param('cat') ?? 0)),
'limit_day' => max(0, (int) ($request->get_param('limit_day') ?? 0)),
'topics' => sanitize_text_field((string) ($request->get_param('topics') ?? '')),
'pay_type' => sanitize_key((string) ($request->get_param('pay_type') ?? '')),
];
$html = \AKSRT\Widgets\WidgetOnelinePosts::render_html($instance);
return new \WP_REST_Response(['success' => true, 'html' => $html], 200);
@@ -193,7 +222,7 @@ class WidgetAjax {
$instance = [
'count' => max(1, min(20, (int) ($request->get_param('count') ?? 5))),
'show_avatar' => $request->get_param('show_avatar') === null ? 1 : (int) $request->get_param('show_avatar'),
'outpost' => max(0, (int) ($request->get_param('outpost') ?? 0)),
'outpost' => sanitize_text_field((string) ($request->get_param('outpost') ?? '')),
'outer' => sanitize_text_field((string) ($request->get_param('outer') ?? '')),
];
$html = \AKSRT\Widgets\RecentCommentsWidget::render_html($instance);