diff --git a/category.php b/category.php
index 43c096d1..9c7f20b3 100644
--- a/category.php
+++ b/category.php
@@ -63,8 +63,8 @@ if (!empty($filter_settings['enabled']) && !in_array('cat', $filter_settings['cu
$ajax_filter = !empty($filter_settings['ajax_enabled']) && !empty($filter_settings['enabled']);
$cat_filter_config = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_filter_config_for_category((int) $term->term_id)
- : ['dimensions' => [], 'show_cat' => true, 'show_tag' => false, 'show_topics' => false, 'show_orderby' => true];
-$custom_dimensions = $cat_filter_config['dimensions'];
+ : ['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' => []];
$current_sort = $sort_state['current'];
$sort_links = $sort_state['links'];
@@ -120,6 +120,74 @@ if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
}
}
+$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 . '"' : '',
+ ];
+ }
+ $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 . '"' : '',
+ ];
+ }
+ $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')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--stream',
@@ -134,86 +202,39 @@ if (function_exists('aksrt_archive_open_shell')) {
-
-
-
+ $header_style,
+ 'show_cover' => !empty($archive_settings['show_cover']),
+ 'cover_url' => (string) ($archive_settings['cover_url'] ?? ''),
+ 'eyebrow' => __('分类归档', 'aksrt'),
+ 'title' => single_cat_title('', false),
+ 'description' => $description,
+ 'admin_path' => 'page-display/category',
+ 'admin_label' => __('分类页设置', 'aksrt'),
+ ]);
+ }
+ ?>
-
-
data-ajax-archive="category" data-term-id="term_id; ?>" data-query-context="archive" data-render-mode="" data-card-style="">
-
-
-
-
-
-
-
-
-
- count, 'aksrt')), (int) $term->count); ?>
-
-
-
-
-
-
-
-
-
-
-
+ $ajax_filter,
+ 'ajax_archive' => 'category',
+ 'term_id' => (int) $term->term_id,
+ 'layout_mode' => $layout_mode,
+ 'card_style' => $card_style,
+ 'aria_label' => __('分类筛选', 'aksrt'),
+ 'meta_text' => 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_current' => $current_sort,
+ 'sort_links' => $sort_links,
+ 'sort_as_main' => false,
+ ]);
+ }
+ ?>
$args Header args.
+ */
+ function aksrt_archive_render_term_header(array $args = []): void {
+ $args = wp_parse_args($args, [
+ 'header_style' => 'simple',
+ 'show_cover' => false,
+ 'cover_url' => '',
+ 'eyebrow' => '',
+ 'title' => '',
+ 'description' => '',
+ 'admin_path' => '',
+ 'admin_label' => '',
+ ]);
+
+ $header_style = (string) $args['header_style'];
+ if ($header_style === 'none') {
+ return;
+ }
+
+ $show_cover = !empty($args['show_cover']) && (string) $args['cover_url'] !== '';
+ $cover_url = (string) $args['cover_url'];
+ ?>
+
+ $chip Chip args.
+ */
+ function aksrt_archive_render_filter_chip(array $chip): void {
+ $chip = wp_parse_args($chip, [
+ 'label' => '',
+ 'url' => '',
+ 'active' => false,
+ 'attrs' => '',
+ ]);
+ if ((string) $chip['label'] === '' || (string) $chip['url'] === '') {
+ return;
+ }
+ ?>
+
>
+ $group Group args.
+ */
+ function aksrt_archive_render_filter_group(array $group): void {
+ $group = wp_parse_args($group, [
+ 'label' => '',
+ 'chips' => [],
+ 'class' => '',
+ ]);
+ $chips = is_array($group['chips'] ?? null) ? $group['chips'] : [];
+ if (empty($chips)) {
+ return;
+ }
+ $class = trim('archive-filter-bar__main ' . (string) $group['class']);
+ ?>
+
+ $args Filter bar args.
+ */
+ function aksrt_archive_render_filter_bar(array $args = []): void {
+ $args = wp_parse_args($args, [
+ 'ajax' => false,
+ 'ajax_archive' => '',
+ 'term_id' => 0,
+ 'layout_mode' => 'card',
+ 'card_style' => 'standard',
+ 'aria_label' => '',
+ 'meta_text' => '',
+ 'groups' => [],
+ 'sort_enabled' => false,
+ 'sort_current' => 'latest',
+ 'sort_links' => [],
+ 'sort_as_main' => false,
+ ]);
+
+ $groups = is_array($args['groups'] ?? null) ? $args['groups'] : [];
+ $sort_links = is_array($args['sort_links'] ?? null) ? $args['sort_links'] : [];
+ $has_sort = !empty($args['sort_enabled']) && !empty($sort_links);
+ if (empty($groups) && !$has_sort && (string) $args['meta_text'] === '') {
+ return;
+ }
+
+ $ajax = !empty($args['ajax']);
+ ?>
+
+ data-ajax-archive=""
+ data-term-id=""
+ data-query-context="archive"
+ data-render-mode=""
+ data-card-style=""
+
+ >
+
+
+
+
+
+
+
+
+
+ $sort_url) {
+ $sort_chips[] = [
+ 'label' => $sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt')),
+ 'url' => (string) $sort_url,
+ 'active' => (string) $args['sort_current'] === (string) $sort_key,
+ 'attrs' => $ajax ? ' data-filter-sort="' . esc_attr((string) $sort_key) . '"' : '',
+ ];
+ }
+ if (!empty($args['sort_as_main'])) {
+ aksrt_archive_render_filter_group([
+ 'label' => __('排序', 'aksrt'),
+ 'chips' => $sort_chips,
+ ]);
+ } else {
+ ?>
+
+
+
+
+
+
+ __('全部', 'aksrt'),
+ 'url' => remove_query_arg(['aksrt_filter_cat']),
+ 'active' => $current_filter_cat === '',
+ 'attrs' => $ajax_filter ? ' data-filter-cat=""' : '',
+ ]];
+ foreach ($cat_filter_terms as $cat_term) {
+ $is_current_cat = ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $cat_term->term_id);
+ $chips[] = [
+ 'label' => $cat_term->name,
+ 'url' => add_query_arg('aksrt_filter_cat', (int) $cat_term->term_id),
+ 'active' => $is_current_cat,
+ 'attrs' => $ajax_filter ? ' data-filter-cat="' . (int) $cat_term->term_id . '"' : '',
+ ];
+ }
+ $filter_groups[] = [
+ 'label' => __('分类', 'aksrt'),
+ 'chips' => $chips,
+ ];
+}
+
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--stream',
@@ -85,62 +108,39 @@ if (function_exists('aksrt_archive_open_shell')) {
-
-
-
+ $header_style,
+ 'show_cover' => !empty($archive_settings['show_cover']),
+ 'cover_url' => (string) ($archive_settings['cover_url'] ?? ''),
+ 'eyebrow' => __('标签归档', 'aksrt'),
+ 'title' => single_tag_title('', false),
+ 'description' => $description,
+ 'admin_path' => 'page-display/tag',
+ 'admin_label' => __('标签页设置', 'aksrt'),
+ ]);
+ }
+ ?>
-
-
data-ajax-archive="tag" data-term-id="term_id; ?>" data-query-context="archive" data-render-mode="" data-card-style="">
-
-
-
-
-
-
-
-
-
- count, 'aksrt')), (int) $term->count); ?>
-
-
-
+ $ajax_filter,
+ 'ajax_archive' => 'tag',
+ 'term_id' => (int) $term->term_id,
+ 'layout_mode' => $layout_mode,
+ 'card_style' => $card_style,
+ 'aria_label' => __('标签工具条', 'aksrt'),
+ 'meta_text' => sprintf(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt'), (int) $term->count),
+ 'groups' => $filter_groups,
+ 'sort_enabled' => !empty($filter_settings['sort']),
+ 'sort_current' => $current_sort,
+ 'sort_links' => $sort_links,
+ 'sort_as_main' => true,
+ ]);
+ }
+ ?>