fix 更多栏目

This commit is contained in:
kate522 committed 2026-09-05 17:32:18 +08:00
1 parent 5b89fc200b
commit 05a6b6fc54
28 files changed
+440 -2295

No files matched your search

+1 -90
View File
@@ -98,21 +98,6 @@ class GlobalController extends ControllerBase {
'permission_callback' => [$this, 'check_permission'],
]);
// Homepage tab posts (public)
register_rest_route(self::API_NAMESPACE, '/homepage/tab-posts', [
'methods' => 'GET',
'callback' => [$this, 'rest_homepage_tab_posts'],
'permission_callback' => '__return_true',
'args' => [
'term_id' => ['type' => 'integer', 'required' => true, 'sanitize_callback' => 'absint'],
'page' => ['type' => 'integer', 'default' => 1, 'sanitize_callback' => 'absint'],
'per_page' => ['type' => 'integer', 'default' => 10, 'sanitize_callback' => 'absint'],
'sort' => ['type' => 'string', 'default' => 'modified', 'sanitize_callback' => 'sanitize_text_field'],
'panel' => ['type' => 'string', 'default' => 'latest', 'sanitize_callback' => 'sanitize_key'],
'tab_orderby' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_key'],
],
]);
// Archive AJAX filter (public) — §2.5/§2.6/§2.7
register_rest_route(self::API_NAMESPACE, '/archive/posts', [
'methods' => 'GET',
@@ -183,81 +168,7 @@ class GlobalController extends ControllerBase {
return $this->success(['message' => '测试邮件已发送']);
}
public function rest_homepage_tab_posts(\WP_REST_Request $request): \WP_REST_Response {
$term_id = (int) $request->get_param('term_id');
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, max(1, (int) $request->get_param('per_page')));
$sort = sanitize_key($request->get_param('sort') ?: 'modified');
$tab_orderby = sanitize_key($request->get_param('tab_orderby') ?: '');
$panel = sanitize_key($request->get_param('panel') ?: 'latest');
$post_types = function_exists('aksrt_homepage_get_post_types')
? aksrt_homepage_get_post_types()
: ['post'];
$args = [
'post_type' => $post_types,
'post_status' => 'publish',
'posts_per_page' => $per_page,
'paged' => $page,
'ignore_sticky_posts' => $term_id > 0,
];
if ($term_id > 0) {
$term = get_term($term_id);
$taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category';
if ($taxonomy !== 'category') {
$taxonomy = 'category';
}
$args['tax_query'] = [[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => [$term_id],
]];
}
$exclude_ids = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_exclude_post_ids()
: [];
if (!empty($exclude_ids)) {
$args['post__not_in'] = $exclude_ids;
}
if ($panel === 'latest' || $term_id <= 0) {
$exclude_cat_ids = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_exclude_category_ids()
: [];
if (!empty($exclude_cat_ids)) {
$args['category__not_in'] = $exclude_cat_ids;
}
}
$effective_sort = $tab_orderby !== '' ? $tab_orderby : $sort;
if (function_exists('aksrt_homepage_apply_named_sort_args')) {
$args = aksrt_homepage_apply_named_sort_args($args, $effective_sort);
} else {
$args['orderby'] = 'date';
$args['order'] = 'DESC';
}
$query = new \WP_Query($args);
$render_config = aksrt_resolve_post_list_render_config([
'context' => 'home',
]);
$render_config['skip_wrapper'] = true;
$html = aksrt_render_post_list($render_config, $query, false);
$has_more = $page < (int) $query->max_num_pages;
return $this->success([
'html' => $html,
'total' => (int) $query->found_posts,
'has_more' => $has_more,
]);
}
public function rest_archive_posts(\WP_REST_Request $request): \WP_REST_Response {
public function rest_archive_posts(\WP_REST_Request $request): \WP_REST_Response {
$archive_type = sanitize_key((string) ($request->get_param('archive_type') ?: 'category'));
$archive_type = in_array($archive_type, ['category', 'tag'], true) ? $archive_type : 'category';
$term_id = absint($request->get_param('term_id'));