Merge pull request '收口 category/tag filter 与 term header 共享层' (#24) from worktree-bg-unified-single-home-mainline into main
Reviewed-on: CYL/wordpress-theme-aksrt#24
This commit is contained in:
+102
-81
@@ -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')) {
|
||||
<div class="content-main content-main--archive content-main--category">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('分类归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_cat_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/category', __('分类页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_term_header')) {
|
||||
aksrt_archive_render_term_header([
|
||||
'header_style' => $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'),
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (!empty($archive_settings['filter_bar']) && (!empty($filter_terms) || !empty($tag_filter_terms) || !empty($custom_dimensions))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('分类筛选', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="category" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类导航', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo (empty($term->parent) && $current_filter_cat === '') ? ' is-active' : ''; ?>" href="<?php echo esc_url($filter_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="0"<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($filter_terms as $filter_term) : ?>
|
||||
<?php $is_current = ((int) $filter_term->term_id === (int) $term->term_id) || ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $filter_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current ? ' is-active' : ''; ?>" href="<?php echo esc_url(get_term_link($filter_term)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $filter_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($filter_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($tag_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--tags">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('标签', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_tag === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_tag'])); ?>"<?php if ($ajax_filter) : ?> data-filter-tag=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($tag_filter_terms as $tag_term) : ?>
|
||||
<?php $is_current_tag = ($current_filter_tag !== '' && (int) $current_filter_tag === (int) $tag_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_tag ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_tag', (int) $tag_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-tag="<?php echo (int) $tag_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($tag_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($filter_settings['enabled']) && !empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__sort" aria-label="<?php esc_attr_e('排序方式', 'aksrt'); ?>">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($custom_dimensions as $dim) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--custom">
|
||||
<span class="archive-filter-bar__label"><?php echo esc_html($dim['name']); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php $cf_all_url = remove_query_arg('aksrt_cf_' . $dim['key']); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo ($current_cf_values[$dim['key']] ?? '') === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url($cf_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($dim['vals'] as $val) : ?>
|
||||
<?php $is_current_cf = ($current_cf_values[$dim['key']] ?? '') === $val['key']; ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cf ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_cf_' . $dim['key'], $val['key'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val="<?php echo esc_attr($val['key']); ?>"<?php endif; ?>><?php echo esc_html($val['name']); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if (!empty($archive_settings['filter_bar']) && function_exists('aksrt_archive_render_filter_bar')) {
|
||||
aksrt_archive_render_filter_bar([
|
||||
'ajax' => $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,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_stream')) {
|
||||
|
||||
@@ -29,6 +29,7 @@ require_once AKSRT_DIR . '/inc/helpers/aksrt-flow.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-homepage.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-single.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive-filters.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-slider.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-vip.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-i18n-switch.php';
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared archive term header / filter bar helpers.
|
||||
*
|
||||
* Loaded by aksrt-archive.php.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_term_header')) :
|
||||
/**
|
||||
* Shared term archive header for category/tag pages.
|
||||
*
|
||||
* @param array<string,mixed> $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'];
|
||||
?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo ($show_cover && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if ($show_cover && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url($cover_url); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<?php if ((string) $args['eyebrow'] !== '') : ?>
|
||||
<p class="term-page-header__eyebrow"><?php echo esc_html((string) $args['eyebrow']); ?></p>
|
||||
<?php endif; ?>
|
||||
<h1 class="entry-title"><?php echo esc_html((string) $args['title']); ?></h1>
|
||||
<?php if ((string) $args['description'] !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $args['description']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
if ((string) $args['admin_path'] !== '' && function_exists('aksrt_render_admin_quick_link')) {
|
||||
aksrt_render_admin_quick_link((string) $args['admin_path'], (string) $args['admin_label']);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php if ($show_cover && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url($cover_url); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_filter_chip')) :
|
||||
/**
|
||||
* One archive filter chip.
|
||||
*
|
||||
* @param array<string,mixed> $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;
|
||||
}
|
||||
?>
|
||||
<a class="archive-filter-bar__chip<?php echo !empty($chip['active']) ? ' is-active' : ''; ?>" href="<?php echo esc_url((string) $chip['url']); ?>"<?php echo $chip['attrs']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><?php echo esc_html((string) $chip['label']); ?></a>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_filter_group')) :
|
||||
/**
|
||||
* One labeled chip group.
|
||||
*
|
||||
* @param array<string,mixed> $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']);
|
||||
?>
|
||||
<div class="<?php echo esc_attr($class); ?>">
|
||||
<?php if ((string) $group['label'] !== '') : ?>
|
||||
<span class="archive-filter-bar__label"><?php echo esc_html((string) $group['label']); ?></span>
|
||||
<?php endif; ?>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php foreach ($chips as $chip) : ?>
|
||||
<?php if (is_array($chip)) { aksrt_archive_render_filter_chip($chip); } ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_filter_bar')) :
|
||||
/**
|
||||
* Shared filter bar shell for category/tag archives.
|
||||
*
|
||||
* @param array<string,mixed> $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']);
|
||||
?>
|
||||
<div
|
||||
class="archive-filter-bar<?php echo $ajax ? ' archive-filter-bar--ajax' : ''; ?>"
|
||||
aria-label="<?php echo esc_attr((string) ($args['aria_label'] !== '' ? $args['aria_label'] : __('筛选', 'aksrt'))); ?>"
|
||||
<?php if ($ajax) : ?>
|
||||
data-ajax-archive="<?php echo esc_attr((string) $args['ajax_archive']); ?>"
|
||||
data-term-id="<?php echo (int) $args['term_id']; ?>"
|
||||
data-query-context="archive"
|
||||
data-render-mode="<?php echo esc_attr((string) $args['layout_mode']); ?>"
|
||||
data-card-style="<?php echo esc_attr((string) $args['card_style']); ?>"
|
||||
<?php endif; ?>
|
||||
>
|
||||
<?php foreach ($groups as $group) : ?>
|
||||
<?php if (is_array($group)) { aksrt_archive_render_filter_group($group); } ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ((string) $args['meta_text'] !== '') : ?>
|
||||
<div class="archive-filter-bar__meta"><?php echo esc_html((string) $args['meta_text']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($has_sort) : ?>
|
||||
<?php
|
||||
$sort_chips = [];
|
||||
foreach ($sort_links as $sort_key => $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 {
|
||||
?>
|
||||
<div class="archive-filter-bar__sort" aria-label="<?php esc_attr_e('排序方式', 'aksrt'); ?>">
|
||||
<?php foreach ($sort_chips as $chip) { aksrt_archive_render_filter_chip($chip); } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
@@ -71,6 +71,29 @@ if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
|
||||
}
|
||||
}
|
||||
|
||||
$filter_groups = [];
|
||||
if (!empty($cat_filter_terms)) {
|
||||
$chips = [[
|
||||
'label' => __('全部', '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')) {
|
||||
<div class="content-main content-main--archive content-main--tag">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('标签归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_tag_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/tag', __('标签页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_term_header')) {
|
||||
aksrt_archive_render_term_header([
|
||||
'header_style' => $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'),
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (!empty($filter_settings['enabled']) && (!empty($filter_settings['sort']) || !empty($cat_filter_terms))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('标签工具条', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="tag" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($cat_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_cat === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_cat'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cat=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($cat_filter_terms as $cat_term) : ?>
|
||||
<?php $is_current_cat = ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $cat_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cat ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_cat', (int) $cat_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $cat_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($cat_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('排序', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if (!empty($filter_settings['enabled']) && function_exists('aksrt_archive_render_filter_bar')) {
|
||||
aksrt_archive_render_filter_bar([
|
||||
'ajax' => $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,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_stream')) {
|
||||
|
||||
Reference in New Issue
Block a user