抽出 aksrt-archive 共享 shell/stream/render config, 四类列表页统一 content-shell + shared renderer + page-owned sidebar。
169 lines
8.2 KiB
PHP
169 lines
8.2 KiB
PHP
<?php
|
|
/**
|
|
* Tag archive template.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
$term = get_queried_object();
|
|
if (!$term instanceof WP_Term) {
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
$archive_settings = class_exists('AKSRT_Term_Meta')
|
|
? AKSRT_Term_Meta::resolve_archive_settings($term)
|
|
: [
|
|
'layout_mode' => 'card',
|
|
'header_style' => 'simple',
|
|
'show_sidebar' => true,
|
|
'show_cover' => false,
|
|
'show_desc' => !empty($term->description),
|
|
'cover_url' => '',
|
|
'description' => (string) $term->description,
|
|
'card_style' => 'standard',
|
|
];
|
|
|
|
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
|
? aksrt_archive_has_sidebar('tag_sidebar', !empty($archive_settings['show_sidebar']))
|
|
: (!empty($archive_settings['show_sidebar']) && (is_active_sidebar('tag_sidebar') || is_active_sidebar('sidebar-blog')));
|
|
$description = !empty($archive_settings['show_desc']) ? wp_kses_post((string) $archive_settings['description']) : '';
|
|
$header_style = (string) $archive_settings['header_style'];
|
|
$layout_mode = (string) $archive_settings['layout_mode'];
|
|
$card_style = (string) ($archive_settings['card_style'] ?? 'standard');
|
|
$filter_settings = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::get_post_filter_settings()
|
|
: ['enabled' => false, 'sort' => false, 'ajax_enabled' => false];
|
|
if (!empty($filter_settings['enabled']) && !in_array('tag', $filter_settings['custom_filter_show'] ?? ['cat', 'tag'], true)) {
|
|
$filter_settings['enabled'] = false;
|
|
}
|
|
$ajax_filter = !empty($filter_settings['ajax_enabled']) && !empty($filter_settings['enabled']);
|
|
$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'];
|
|
$render_config = function_exists('aksrt_archive_get_render_config')
|
|
? aksrt_archive_get_render_config([
|
|
'context' => 'tag',
|
|
'mode' => $layout_mode,
|
|
'card_style' => $card_style,
|
|
])
|
|
: [
|
|
'context' => 'tag',
|
|
'mode' => $layout_mode,
|
|
'card_style' => $card_style,
|
|
];
|
|
|
|
$cat_filter_terms = [];
|
|
$current_filter_cat = sanitize_text_field((string) get_query_var('aksrt_filter_cat', ''));
|
|
if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
|
|
$cat_filter_terms = get_terms([
|
|
'taxonomy' => 'category',
|
|
'hide_empty' => true,
|
|
'parent' => 0,
|
|
'number' => 20,
|
|
]);
|
|
if (is_wp_error($cat_filter_terms)) {
|
|
$cat_filter_terms = [];
|
|
}
|
|
}
|
|
|
|
if (function_exists('aksrt_archive_open_shell')) {
|
|
aksrt_archive_open_shell([
|
|
'main_class' => 'site-main container content-shell content-shell--stream',
|
|
'has_sidebar' => $has_sidebar,
|
|
'top_fluid' => ['tag_top_fluid'],
|
|
'page_kind' => 'tag',
|
|
]);
|
|
}
|
|
?>
|
|
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['tag_top_content']); } elseif (is_active_sidebar('tag_top_content')) { dynamic_sidebar('tag_top_content'); } ?>
|
|
|
|
<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 (!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 (function_exists('aksrt_archive_render_stream')) {
|
|
aksrt_archive_render_stream(null, $render_config, [
|
|
'page_kind' => 'tag',
|
|
'query_context' => 'archive',
|
|
'stream_class' => 'archive__ajax-wrap content-stream--archive content-stream--tag',
|
|
'empty_text' => __('该标签下暂无文章', 'aksrt'),
|
|
'ajax_enabled' => $ajax_filter,
|
|
'show_loading' => $ajax_filter,
|
|
]);
|
|
}
|
|
?>
|
|
|
|
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['tag_bottom_content']); } elseif (is_active_sidebar('tag_bottom_content')) { dynamic_sidebar('tag_bottom_content'); } ?>
|
|
</div>
|
|
<?php
|
|
if (function_exists('aksrt_archive_close_shell')) {
|
|
aksrt_archive_close_shell([
|
|
'has_sidebar' => $has_sidebar,
|
|
'bottom_fluid' => ['tag_bottom_fluid'],
|
|
]);
|
|
}
|
|
|
|
get_footer();
|