From 1de0cac8df254639f5b295f7af4125d81ce58955 Mon Sep 17 00:00:00 2001
From: unknown
Date: Tue, 21 Jul 2026 13:13:07 +0800
Subject: [PATCH] feat(widgets): number paginate for category
block/recent/product tab
Extend form/query/REST number pager support to category block and forum
recent; product tab form exposes number mode already supported by list.
---
src/AKSRT/Widgets/CategoryBlockWidget.php | 32 +++++++++++--------
src/AKSRT/Widgets/WidgetForumRecentTopics.php | 3 +-
2 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/src/AKSRT/Widgets/CategoryBlockWidget.php b/src/AKSRT/Widgets/CategoryBlockWidget.php
index 80f72769..953c6773 100644
--- a/src/AKSRT/Widgets/CategoryBlockWidget.php
+++ b/src/AKSRT/Widgets/CategoryBlockWidget.php
@@ -337,7 +337,7 @@ class CategoryBlockWidget extends \WP_Widget {
$context
);
$paginate = sanitize_key((string) ($instance['paginate'] ?? 'none'));
- if (!in_array($paginate, ['ajax', 'none'], true)) {
+ if (!in_array($paginate, ['ajax', 'none', 'number'], true)) {
$paginate = 'none';
}
@@ -367,21 +367,26 @@ class CategoryBlockWidget extends \WP_Widget {
$max_pages = max(1, (int) $query->max_num_pages);
$total = (int) $query->found_posts;
- $has_more = $paginate === 'ajax' && $page < $max_pages;
+ $has_more = in_array($paginate, ['ajax', 'number'], true) && $page < $max_pages;
+ $base_qs = [
+ 'count' => $count,
+ 'cat' => $category_id,
+ 'columns' => $columns,
+ 'layout' => $layout,
+ 'context' => $context,
+ 'paginate' => $paginate,
+ ];
+ $rest_base = add_query_arg($base_qs, rest_url('aksrt/v1/widgets/category-block'));
$paginate_html = '';
if ($paginate === 'ajax' && $has_more) {
- $next = add_query_arg([
- 'page' => $page + 1,
- 'count' => $count,
- 'cat' => $category_id,
- 'columns' => $columns,
- 'layout' => $layout,
- 'context' => $context,
- 'paginate' => 'ajax',
- ], rest_url('aksrt/v1/widgets/category-block'));
+ $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)
: '';
+ } 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)
+ : '';
} else {
$paginate_html = '';
}
@@ -397,7 +402,7 @@ class CategoryBlockWidget extends \WP_Widget {
$title = $title !== '' ? $title : (($term && ! is_wp_error($term)) ? $term->name : __('精选分类', 'aksrt'));
$show_more = ! empty($instance['show_more']);
$paginate = sanitize_key((string) ($instance['paginate'] ?? 'none'));
- if (!in_array($paginate, ['ajax', 'none'], true)) {
+ if (!in_array($paginate, ['ajax', 'none', 'number'], true)) {
$paginate = 'none';
}
$instance['paginate'] = $paginate;
@@ -475,6 +480,7 @@ class CategoryBlockWidget extends \WP_Widget {
@@ -490,7 +496,7 @@ class CategoryBlockWidget extends \WP_Widget {
'columns' => max(1, min(4, absint($new_instance['columns'] ?? 3))),
'layout' => aksrt_home_widget_resolve_layout($new_instance['layout'] ?? 'card', 'card'),
'show_more' => ! empty($new_instance['show_more']) ? 1 : 0,
- 'paginate' => sanitize_key((string) ($new_instance['paginate'] ?? 'none')) === 'ajax' ? 'ajax' : 'none',
+ 'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'none')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'none')) : 'none',
];
}
diff --git a/src/AKSRT/Widgets/WidgetForumRecentTopics.php b/src/AKSRT/Widgets/WidgetForumRecentTopics.php
index 5750f31d..b48a93c5 100644
--- a/src/AKSRT/Widgets/WidgetForumRecentTopics.php
+++ b/src/AKSRT/Widgets/WidgetForumRecentTopics.php
@@ -79,6 +79,7 @@ class WidgetForumRecentTopics extends \WP_Widget {
@@ -96,7 +97,7 @@ class WidgetForumRecentTopics extends \WP_Widget {
'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',
+ 'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) : 'ajax',
];
}
}