feat(homepage): consume Zibll homepage keys on frontend queries

Point homepage getters and tab queries at home_lists / home_exclude_* /
index_list_title / list1 orderby. Support category+topics tab terms via
tax_query, expand the homepage term picker API, and keep facade method
names for existing templates without dual-writing storage keys.
This commit is contained in:
2026-07-11 15:23:21 +08:00
parent 0c882d8887
commit f0f6e97d04
4 changed files with 76 additions and 15 deletions
@@ -295,8 +295,8 @@ async function loadCategories() {
const res = await api.getHomepageCategories()
const cats = res?.data || []
categoryOptions.value = cats.map(c => ({
label: `${c.name} (${c.count})`,
value: c.term_id,
label: `${c.taxonomy === 'topics' ? '[专题] ' : ''}${c.name} (${c.count})`,
value: c.term_id || c.id,
}))
} catch {
// non-critical
@@ -263,7 +263,16 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
];
if ($term_id > 0) {
$args['cat'] = $term_id;
$term = get_term($term_id);
$taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category';
if (!in_array($taxonomy, ['category', 'topics'], true)) {
$taxonomy = 'category';
}
$args['tax_query'] = [[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => [$term_id],
]];
}
$exclude_ids = class_exists('AKSRT_Settings')
@@ -327,11 +336,43 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
}
public function rest_homepage_categories(): WP_REST_Response {
$cats = get_categories(['hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC']);
$data = [];
$cats = get_categories(['hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC']);
foreach ($cats as $cat) {
$data[] = ['id' => $cat->term_id, 'name' => $cat->name, 'slug' => $cat->slug, 'count' => $cat->count, 'parent' => $cat->parent];
$data[] = [
'id' => (int) $cat->term_id,
'term_id' => (int) $cat->term_id,
'name' => $cat->name,
'slug' => $cat->slug,
'count' => (int) $cat->count,
'parent' => (int) $cat->parent,
'taxonomy' => 'category',
];
}
if (taxonomy_exists('topics')) {
$topics = get_terms([
'taxonomy' => 'topics',
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
]);
if (!is_wp_error($topics)) {
foreach ($topics as $term) {
$data[] = [
'id' => (int) $term->term_id,
'term_id' => (int) $term->term_id,
'name' => $term->name,
'slug' => $term->slug,
'count' => (int) $term->count,
'parent' => (int) $term->parent,
'taxonomy' => 'topics',
];
}
}
}
return $this->success(['data' => $data]);
}
@@ -266,7 +266,12 @@ class AKSRT_Settings_Home_Cms {
public static function homepage_tabs(): array {
$settings = self::get_homepage_fixed_settings();
return $settings['homepage_tabs'];
return $settings['home_lists'];
}
/** @return array<int, array{term_id:int,title:string,orderby:string,enabled:bool}> */
public static function home_lists(): array {
return self::homepage_tabs();
}
public static function homepage_card_style(): string {
@@ -291,7 +296,7 @@ class AKSRT_Settings_Home_Cms {
public static function homepage_default_sort(): string {
$settings = self::get_homepage_fixed_settings();
return $settings['homepage_default_sort'];
return $settings['home_list1_orderby_option']['orderby'] ?? 'modified';
}
public static function homepage_default_view(): string {
@@ -311,22 +316,22 @@ class AKSRT_Settings_Home_Cms {
public static function home_posts_list_enabled(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['home_posts_list_enabled']);
return !empty($settings['home_posts_list_s']);
}
public static function home_list_title(): string {
$settings = self::get_homepage_fixed_settings();
return (string) $settings['home_list_title'];
return (string) $settings['index_list_title'];
}
public static function home_list_sort_enabled(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['home_list_sort_enabled']);
return !empty($settings['home_list1_orderby_s']);
}
public static function home_list_sort_options(): array {
$settings = self::get_homepage_fixed_settings();
return $settings['home_list_sort_options'];
return $settings['home_list1_orderby_option']['options'] ?? ['modified', 'date', 'views', 'likes', 'comments'];
}
public static function home_list_sort_dropdown(): bool {
@@ -336,12 +341,12 @@ class AKSRT_Settings_Home_Cms {
public static function home_exclude_post_ids(): array {
$settings = self::get_homepage_fixed_settings();
return $settings['home_exclude_post_ids'];
return $settings['home_exclude_posts'];
}
public static function home_exclude_category_ids(): array {
$settings = self::get_homepage_fixed_settings();
return $settings['home_exclude_category_ids'];
return $settings['home_exclude_cats'];
}
public static function homepage_tab_posts_per_page(): int {
+17 -2
View File
@@ -97,10 +97,13 @@ if (!function_exists('aksrt_homepage_get_tab_terms')) {
continue;
}
$term = get_term($tab['term_id'], 'category');
$term = get_term($tab['term_id']);
if (!$term || is_wp_error($term)) {
continue;
}
if (!in_array($term->taxonomy, ['category', 'topics'], true)) {
continue;
}
$configs[] = [
'term' => $term,
@@ -436,6 +439,12 @@ if (!function_exists('aksrt_homepage_get_tab_query')) {
return $queries[$cache_key];
}
$term = get_term($term_id);
$taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category';
if (!in_array($taxonomy, ['category', 'topics'], true)) {
$taxonomy = 'category';
}
$query_args = [
'post_type' => aksrt_homepage_get_post_types(),
'post_status' => 'publish',
@@ -445,8 +454,14 @@ if (!function_exists('aksrt_homepage_get_tab_query')) {
'ignore_sticky_posts' => true,
'orderby' => 'date',
'order' => 'DESC',
'cat' => $term_id,
'no_found_rows' => true,
'tax_query' => [
[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => [$term_id],
],
],
];
$exclude_ids = class_exists('AKSRT_Settings')