Merge pull request 'feat(homepage): consume Zibll homepage keys on frontend queries' (#50) from worktree-homepage-frontend-keys into main
Reviewed-on: CYL/wordpress-theme-aksrt#50
This commit is contained in:
commit
f86513dbff
4 files changed
+76
-15
No files matched your search
@@ -295,8 +295,8 @@ async function loadCategories() {
|
|||||||
const res = await api.getHomepageCategories()
|
const res = await api.getHomepageCategories()
|
||||||
const cats = res?.data || []
|
const cats = res?.data || []
|
||||||
categoryOptions.value = cats.map(c => ({
|
categoryOptions.value = cats.map(c => ({
|
||||||
label: `${c.name} (${c.count})`,
|
label: `${c.taxonomy === 'topics' ? '[专题] ' : ''}${c.name} (${c.count})`,
|
||||||
value: c.term_id,
|
value: c.term_id || c.id,
|
||||||
}))
|
}))
|
||||||
} catch {
|
} catch {
|
||||||
// non-critical
|
// non-critical
|
||||||
|
|||||||
@@ -263,7 +263,16 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($term_id > 0) {
|
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')
|
$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 {
|
public function rest_homepage_categories(): WP_REST_Response {
|
||||||
$cats = get_categories(['hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC']);
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
|
$cats = get_categories(['hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC']);
|
||||||
foreach ($cats as $cat) {
|
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]);
|
return $this->success(['data' => $data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,12 @@ class AKSRT_Settings_Home_Cms {
|
|||||||
|
|
||||||
public static function homepage_tabs(): array {
|
public static function homepage_tabs(): array {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function homepage_card_style(): string {
|
||||||
@@ -291,7 +296,7 @@ class AKSRT_Settings_Home_Cms {
|
|||||||
|
|
||||||
public static function homepage_default_sort(): string {
|
public static function homepage_default_sort(): string {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function homepage_default_view(): string {
|
||||||
@@ -311,22 +316,22 @@ class AKSRT_Settings_Home_Cms {
|
|||||||
|
|
||||||
public static function home_posts_list_enabled(): bool {
|
public static function home_posts_list_enabled(): bool {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function home_list_title(): string {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function home_list_sort_enabled(): bool {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function home_list_sort_options(): array {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
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 {
|
public static function home_exclude_post_ids(): array {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function home_exclude_category_ids(): array {
|
||||||
$settings = self::get_homepage_fixed_settings();
|
$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 {
|
public static function homepage_tab_posts_per_page(): int {
|
||||||
|
|||||||
@@ -97,10 +97,13 @@ if (!function_exists('aksrt_homepage_get_tab_terms')) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$term = get_term($tab['term_id'], 'category');
|
$term = get_term($tab['term_id']);
|
||||||
if (!$term || is_wp_error($term)) {
|
if (!$term || is_wp_error($term)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!in_array($term->taxonomy, ['category', 'topics'], true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$configs[] = [
|
$configs[] = [
|
||||||
'term' => $term,
|
'term' => $term,
|
||||||
@@ -436,6 +439,12 @@ if (!function_exists('aksrt_homepage_get_tab_query')) {
|
|||||||
return $queries[$cache_key];
|
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 = [
|
$query_args = [
|
||||||
'post_type' => aksrt_homepage_get_post_types(),
|
'post_type' => aksrt_homepage_get_post_types(),
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
@@ -445,8 +454,14 @@ if (!function_exists('aksrt_homepage_get_tab_query')) {
|
|||||||
'ignore_sticky_posts' => true,
|
'ignore_sticky_posts' => true,
|
||||||
'orderby' => 'date',
|
'orderby' => 'date',
|
||||||
'order' => 'DESC',
|
'order' => 'DESC',
|
||||||
'cat' => $term_id,
|
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
|
'tax_query' => [
|
||||||
|
[
|
||||||
|
'taxonomy' => $taxonomy,
|
||||||
|
'field' => 'term_id',
|
||||||
|
'terms' => [$term_id],
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$exclude_ids = class_exists('AKSRT_Settings')
|
$exclude_ids = class_exists('AKSRT_Settings')
|
||||||
|
|||||||
Reference in new issue
Block a user