fix 更多栏目
This commit is contained in:
@@ -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'));
|
||||
|
||||
@@ -367,18 +367,6 @@ trait ScriptsPart1c {
|
||||
);
|
||||
}
|
||||
|
||||
if ($is_fixed_homepage) {
|
||||
$homepage_js_path = get_template_directory() . '/assets/js/homepage-fixed.js';
|
||||
wp_enqueue_script(
|
||||
'aksrt-homepage-fixed',
|
||||
$base_uri . '/assets/js/homepage-fixed.js',
|
||||
['loader_js'],
|
||||
file_exists($homepage_js_path) ? (string) filemtime($homepage_js_path) : $version,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Comment toolbar (code/image/link shortcodes) — post form.
|
||||
$load_comment_tools = !empty($singular_assets['needs_comment_tools']);
|
||||
if ($load_comment_tools) {
|
||||
@@ -476,12 +464,6 @@ trait ScriptsPart1c {
|
||||
'debugLog' => defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG,
|
||||
'postPaginationMode' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_pagination_mode() : 'load_more',
|
||||
'commentPaginationMode' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_comment_pagination_mode() : 'numbered',
|
||||
'homepagePostsPerPage' => function_exists('aksrt_homepage_get_tab_posts_per_page') ? aksrt_homepage_get_tab_posts_per_page() : (int) get_option('posts_per_page'),
|
||||
'homepageDefaultSort' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::homepage_default_sort() : 'modified',
|
||||
'homepageStickyTabs' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::homepage_sticky_tabs_enabled() : true,
|
||||
'homePostsListEnabled' => !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::home_posts_list_enabled(),
|
||||
'homeListSortEnabled' => !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::home_list_sort_enabled(),
|
||||
'homeListSortDropdown' => class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::home_list_sort_dropdown(),
|
||||
// AJAX 翻页文案
|
||||
'ajaxTrigger' => (class_exists('\AKSRT\Settings\Settings') && ($t = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_trigger'] ?? '') !== '') ? $t : '<i class="fa fas fa-angle-right"></i>加载更多',
|
||||
'ajaxNomore' => (class_exists('\AKSRT\Settings\Settings') && ($n = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_nomore'] ?? '') !== '') ? $n : __('没有更多内容了', 'aksrt'),
|
||||
|
||||
@@ -175,10 +175,6 @@ class HomeCms {
|
||||
return $settings['home_list1_orderby_option']['lists'][0] ?? 'modified';
|
||||
}
|
||||
|
||||
public static function homepage_sticky_tabs_enabled(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function home_posts_list_enabled(): bool {
|
||||
$settings = self::get_homepage_fixed_settings();
|
||||
return !empty($settings['home_posts_list_s']);
|
||||
@@ -214,10 +210,6 @@ class HomeCms {
|
||||
return $settings['home_exclude_cats'];
|
||||
}
|
||||
|
||||
public static function homepage_tab_posts_per_page(): int {
|
||||
return 6;
|
||||
}
|
||||
|
||||
public static function get_paid_content_settings(): array {
|
||||
return PaymentRuntime::get_paid_content_settings();
|
||||
}
|
||||
@@ -299,9 +291,9 @@ class HomeCms {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderby = sanitize_key($tab['orderby'] ?? 'modified');
|
||||
if (!in_array($orderby, $allowed_orderby, true)) {
|
||||
$orderby = 'modified';
|
||||
$orderby = sanitize_key((string) ($tab['orderby'] ?? ''));
|
||||
if ($orderby !== '' && !in_array($orderby, $allowed_orderby, true)) {
|
||||
$orderby = '';
|
||||
}
|
||||
|
||||
$tabs[] = [
|
||||
|
||||
@@ -68,13 +68,6 @@ trait HomepageReader {
|
||||
return HomeCms::homepage_default_sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the homepage tabs should use sticky/affix behaviour.
|
||||
*/
|
||||
public static function homepage_sticky_tabs_enabled(): bool {
|
||||
return HomeCms::homepage_sticky_tabs_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the main "latest posts" list is enabled on the homepage.
|
||||
*/
|
||||
@@ -130,13 +123,6 @@ trait HomepageReader {
|
||||
return HomeCms::home_exclude_category_ids();
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts per page for each category tab.
|
||||
*/
|
||||
public static function homepage_tab_posts_per_page(): int {
|
||||
return HomeCms::homepage_tab_posts_per_page();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页脚配色配置
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user