diff --git a/assets/admin/src/pages/content/HomepageSettings.vue b/assets/admin/src/pages/content/HomepageSettings.vue index 0ca5bf41..1d914422 100644 --- a/assets/admin/src/pages/content/HomepageSettings.vue +++ b/assets/admin/src/pages/content/HomepageSettings.vue @@ -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 diff --git a/inc/classes/admin/class-aksrt-admin-global-controller.php b/inc/classes/admin/class-aksrt-admin-global-controller.php index b45969fe..6c270ad3 100644 --- a/inc/classes/admin/class-aksrt-admin-global-controller.php +++ b/inc/classes/admin/class-aksrt-admin-global-controller.php @@ -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]); } diff --git a/inc/classes/settings/class-aksrt-settings-home-cms.php b/inc/classes/settings/class-aksrt-settings-home-cms.php index a9e1f397..dd608569 100644 --- a/inc/classes/settings/class-aksrt-settings-home-cms.php +++ b/inc/classes/settings/class-aksrt-settings-home-cms.php @@ -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 */ + 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 { diff --git a/inc/helpers/aksrt-homepage.php b/inc/helpers/aksrt-homepage.php index 27d3c5c1..4f244a2d 100644 --- a/inc/helpers/aksrt-homepage.php +++ b/inc/helpers/aksrt-homepage.php @@ -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')