feat(admin): rebuild page display settings
This commit is contained in:
+15
-116
@@ -50,130 +50,28 @@ $has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
||||
: (!empty($archive_settings['show_sidebar']) && is_active_sidebar('cat_sidebar'));
|
||||
$description = !empty($archive_settings['show_desc']) ? wp_kses_post((string) $archive_settings['description']) : '';
|
||||
$header_style = (string) $archive_settings['header_style'];
|
||||
$filter_settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_post_filter_settings()
|
||||
: ['enabled' => false, 'sort' => false, 'ajax_enabled' => false];
|
||||
if (!empty($filter_settings['enabled']) && !in_array('cat', $filter_settings['custom_filter_show'] ?? ['cat', 'tag'], true)) {
|
||||
$filter_settings['enabled'] = false;
|
||||
}
|
||||
$ajax_filter = !empty($filter_settings['ajax_enabled']) && !empty($filter_settings['enabled']);
|
||||
$cat_filter_config = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_filter_config_for_category((int) $term->term_id)
|
||||
: ['dimensions' => []];
|
||||
$custom_dimensions = is_array($cat_filter_config['dimensions'] ?? null) ? $cat_filter_config['dimensions'] : [];
|
||||
$sort_state = function_exists('aksrt_archive_get_sort_state') ? aksrt_archive_get_sort_state() : ['current' => 'latest', 'links' => []];
|
||||
$ajax_filter = !empty($archive_settings['filter_bar']);
|
||||
$sort_state = function_exists('aksrt_archive_get_sort_state')
|
||||
? aksrt_archive_get_sort_state((array) ($archive_settings['orderby_option'] ?? []))
|
||||
: ['current' => 'date', 'links' => []];
|
||||
$current_sort = $sort_state['current'];
|
||||
$sort_links = $sort_state['links'];
|
||||
$render_config = function_exists('aksrt_archive_get_render_config')
|
||||
? aksrt_archive_get_render_config(['context' => 'category'])
|
||||
: ['context' => 'category'];
|
||||
|
||||
$filter_terms = [];
|
||||
$filter_all_url = get_category_link($term->term_id);
|
||||
if (!empty($archive_settings['filter_bar'])) {
|
||||
$filter_terms = get_terms([
|
||||
'taxonomy' => 'category',
|
||||
'hide_empty' => true,
|
||||
'parent' => $term->term_id,
|
||||
]);
|
||||
if (empty($filter_terms) && !empty($term->parent)) {
|
||||
$filter_all_url = get_category_link((int) $term->parent);
|
||||
$filter_terms = get_terms([
|
||||
'taxonomy' => 'category',
|
||||
'hide_empty' => true,
|
||||
'parent' => (int) $term->parent,
|
||||
]);
|
||||
}
|
||||
if (is_wp_error($filter_terms)) {
|
||||
$filter_terms = [];
|
||||
}
|
||||
}
|
||||
|
||||
$tag_filter_terms = [];
|
||||
$current_filter_cat = sanitize_text_field((string) get_query_var('aksrt_filter_cat', ''));
|
||||
$current_filter_tag = sanitize_text_field((string) get_query_var('aksrt_filter_tag', ''));
|
||||
$current_cf_values = [];
|
||||
foreach ($custom_dimensions as $dim) {
|
||||
$cf_key = 'aksrt_cf_' . $dim['key'];
|
||||
$current_cf_values[$dim['key']] = isset($_GET[$cf_key]) ? sanitize_key((string) $_GET[$cf_key]) : '';
|
||||
}
|
||||
if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
|
||||
$tag_filter_terms = get_terms([
|
||||
'taxonomy' => 'post_tag',
|
||||
'hide_empty' => true,
|
||||
'number' => 20,
|
||||
]);
|
||||
if (is_wp_error($tag_filter_terms)) {
|
||||
$tag_filter_terms = [];
|
||||
}
|
||||
}
|
||||
|
||||
$filter_groups = [];
|
||||
if (!empty($filter_terms)) {
|
||||
$chips = [[
|
||||
'label' => __('全部', 'aksrt'),
|
||||
'url' => $filter_all_url,
|
||||
'active' => empty($term->parent) && $current_filter_cat === '',
|
||||
'attrs' => $ajax_filter ? ' data-filter-cat="0"' : '',
|
||||
]];
|
||||
foreach ($filter_terms as $filter_term) {
|
||||
$is_current = ((int) $filter_term->term_id === (int) $term->term_id)
|
||||
|| ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $filter_term->term_id);
|
||||
$chips[] = [
|
||||
'label' => $filter_term->name,
|
||||
'url' => get_term_link($filter_term),
|
||||
'active' => $is_current,
|
||||
'attrs' => $ajax_filter ? ' data-filter-cat="' . (int) $filter_term->term_id . '"' : '',
|
||||
];
|
||||
if (!empty($archive_settings['ajax_category_enabled']) && function_exists('aksrt_archive_build_term_filter_group')) {
|
||||
$group = aksrt_archive_build_term_filter_group('category', (array) ($archive_settings['ajax_category'] ?? []), __('分类', 'aksrt'), $ajax_filter);
|
||||
if ($group !== []) {
|
||||
$filter_groups[] = $group;
|
||||
}
|
||||
$filter_groups[] = [
|
||||
'label' => __('分类导航', 'aksrt'),
|
||||
'chips' => $chips,
|
||||
];
|
||||
}
|
||||
if (!empty($tag_filter_terms)) {
|
||||
$chips = [[
|
||||
'label' => __('全部', 'aksrt'),
|
||||
'url' => remove_query_arg(['aksrt_filter_tag']),
|
||||
'active' => $current_filter_tag === '',
|
||||
'attrs' => $ajax_filter ? ' data-filter-tag=""' : '',
|
||||
]];
|
||||
foreach ($tag_filter_terms as $tag_term) {
|
||||
$is_current_tag = ($current_filter_tag !== '' && (int) $current_filter_tag === (int) $tag_term->term_id);
|
||||
$chips[] = [
|
||||
'label' => $tag_term->name,
|
||||
'url' => add_query_arg('aksrt_filter_tag', (int) $tag_term->term_id),
|
||||
'active' => $is_current_tag,
|
||||
'attrs' => $ajax_filter ? ' data-filter-tag="' . (int) $tag_term->term_id . '"' : '',
|
||||
];
|
||||
if (!empty($archive_settings['ajax_tag_enabled']) && function_exists('aksrt_archive_build_term_filter_group')) {
|
||||
$group = aksrt_archive_build_term_filter_group('post_tag', (array) ($archive_settings['ajax_tag'] ?? []), __('标签', 'aksrt'), $ajax_filter);
|
||||
if ($group !== []) {
|
||||
$filter_groups[] = $group;
|
||||
}
|
||||
$filter_groups[] = [
|
||||
'label' => __('标签', 'aksrt'),
|
||||
'class' => 'archive-filter-bar__main--tags',
|
||||
'chips' => $chips,
|
||||
];
|
||||
}
|
||||
foreach ($custom_dimensions as $dim) {
|
||||
$chips = [[
|
||||
'label' => __('全部', 'aksrt'),
|
||||
'url' => remove_query_arg('aksrt_cf_' . $dim['key']),
|
||||
'active' => ($current_cf_values[$dim['key']] ?? '') === '',
|
||||
'attrs' => $ajax_filter ? ' data-filter-cf="' . esc_attr($dim['key']) . '" data-filter-cf-val=""' : '',
|
||||
]];
|
||||
foreach ($dim['vals'] as $val) {
|
||||
$is_current_cf = ($current_cf_values[$dim['key']] ?? '') === $val['key'];
|
||||
$chips[] = [
|
||||
'label' => $val['name'],
|
||||
'url' => add_query_arg('aksrt_cf_' . $dim['key'], $val['key']),
|
||||
'active' => $is_current_cf,
|
||||
'attrs' => $ajax_filter ? ' data-filter-cf="' . esc_attr($dim['key']) . '" data-filter-cf-val="' . esc_attr($val['key']) . '"' : '',
|
||||
];
|
||||
}
|
||||
$filter_groups[] = [
|
||||
'label' => $dim['name'],
|
||||
'class' => 'archive-filter-bar__main--custom',
|
||||
'chips' => $chips,
|
||||
];
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_archive_open_shell')) {
|
||||
@@ -212,11 +110,12 @@ if (function_exists('aksrt_archive_open_shell')) {
|
||||
'ajax_archive' => 'category',
|
||||
'term_id' => (int) $term->term_id,
|
||||
'aria_label' => __('分类筛选', 'aksrt'),
|
||||
'meta_text' => sprintf(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt'), (int) $term->count),
|
||||
'meta_text' => !empty($archive_settings['post_count']) ? sprintf(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt'), (int) $term->count) : '',
|
||||
'groups' => $filter_groups,
|
||||
'sort_enabled' => !empty($filter_settings['enabled']) && !empty($filter_settings['sort']),
|
||||
'sort_enabled' => !empty($archive_settings['orderby_enabled']),
|
||||
'sort_current' => $current_sort,
|
||||
'sort_links' => $sort_links,
|
||||
'sort_labels' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::homepage_sort_labels() : [],
|
||||
'sort_as_main' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user