155 lines
5.5 KiB
PHP
155 lines
5.5 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\Core\TermMeta')
|
|
? \AKSRT\Core\TermMeta::resolve_archive_settings($term)
|
|
: [
|
|
'header_style' => 'simple',
|
|
'show_sidebar' => true,
|
|
'show_cover' => false,
|
|
'show_desc' => !empty($term->description),
|
|
'cover_url' => '',
|
|
'description' => (string) $term->description,
|
|
];
|
|
|
|
$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'));
|
|
$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('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'])
|
|
: ['context' => 'tag'];
|
|
|
|
$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 = [];
|
|
}
|
|
}
|
|
|
|
$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',
|
|
'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 (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']) && function_exists('aksrt_archive_render_filter_bar')) {
|
|
aksrt_archive_render_filter_bar([
|
|
'ajax' => $ajax_filter,
|
|
'ajax_archive' => 'tag',
|
|
'term_id' => (int) $term->term_id,
|
|
'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')) {
|
|
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();
|