Remove deprecated widget locations and widgets, standardize sidebar labels, and render a compact paid-post purchase card in the article sidebar.
266 lines
9.7 KiB
PHP
266 lines
9.7 KiB
PHP
<?php
|
|
/**
|
|
* Category archive template.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
$term = get_queried_object();
|
|
if (class_exists('\AKSRT\Core\DocsPresenter')) {
|
|
$docs_presenter = \AKSRT\Core\DocsPresenter::get_instance();
|
|
if ($term instanceof WP_Term && $term->taxonomy === 'category') {
|
|
$doc_candidates = get_posts([
|
|
'post_type' => 'page',
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => 1,
|
|
'meta_key' => '_aksrt_doc_category',
|
|
'meta_value' => (string) $term->term_id,
|
|
'fields' => 'ids',
|
|
]);
|
|
if (!empty($doc_candidates)) {
|
|
get_template_part('templates/pages/page-documentnav');
|
|
get_footer();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (!$term instanceof WP_Term) {
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
$archive_settings = class_exists('\AKSRT\Core\TermMeta')
|
|
? \AKSRT\Core\TermMeta::resolve_archive_settings($term)
|
|
: [
|
|
'layout_mode' => 'card',
|
|
'header_style' => 'cover',
|
|
'show_sidebar' => true,
|
|
'show_cover' => false,
|
|
'show_desc' => !empty($term->description),
|
|
'filter_bar' => true,
|
|
'cover_url' => '',
|
|
'description' => (string) $term->description,
|
|
'card_style' => 'standard',
|
|
];
|
|
|
|
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
|
? aksrt_archive_has_sidebar('cat_sidebar', !empty($archive_settings['show_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'];
|
|
$layout_mode = (string) $archive_settings['layout_mode'];
|
|
$card_style = (string) ($archive_settings['card_style'] ?? 'standard');
|
|
$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' => []];
|
|
$current_sort = $sort_state['current'];
|
|
$sort_links = $sort_state['links'];
|
|
$render_overrides = [
|
|
'context' => 'category',
|
|
];
|
|
// Term meta layout_mode is authoritative only when explicitly set (non-empty preset).
|
|
$layout_preset = (string) ($archive_settings['layout_preset'] ?? '');
|
|
if ($layout_preset !== '' && in_array((string) $layout_mode, ['list', 'card', 'mini', 'grid-cms'], true)) {
|
|
$render_overrides['mode'] = (string) $layout_mode;
|
|
if (!empty($card_style)) {
|
|
$render_overrides['card_style'] = (string) $card_style;
|
|
}
|
|
}
|
|
$render_config = function_exists('aksrt_archive_get_render_config')
|
|
? aksrt_archive_get_render_config($render_overrides)
|
|
: array_merge(['context' => 'category', 'mode' => 'list'], $render_overrides);
|
|
|
|
$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 . '"' : '',
|
|
];
|
|
}
|
|
$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',
|
|
'has_sidebar' => $has_sidebar,
|
|
'top_fluid' => ['cat_top_fluid'],
|
|
'page_kind' => 'category',
|
|
]);
|
|
}
|
|
?>
|
|
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['cat_top_content']); } elseif (is_active_sidebar('cat_top_content')) { dynamic_sidebar('cat_top_content'); } ?>
|
|
|
|
<div class="content-main content-main--archive content-main--category">
|
|
<?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_cat_title('', false),
|
|
'description' => $description,
|
|
'admin_path' => 'page-display/category',
|
|
'admin_label' => __('分类页设置', 'aksrt'),
|
|
]);
|
|
}
|
|
?>
|
|
|
|
<?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')) {
|
|
aksrt_archive_render_stream(null, $render_config, [
|
|
'page_kind' => 'category',
|
|
'query_context' => 'archive',
|
|
'stream_class' => 'archive__ajax-wrap content-stream--archive content-stream--category',
|
|
'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(['cat_bottom_content']); } elseif (is_active_sidebar('cat_bottom_content')) { dynamic_sidebar('cat_bottom_content'); } ?>
|
|
</div>
|
|
<?php
|
|
if (function_exists('aksrt_archive_close_shell')) {
|
|
aksrt_archive_close_shell([
|
|
'has_sidebar' => $has_sidebar,
|
|
'bottom_fluid' => ['cat_bottom_fluid'],
|
|
]);
|
|
}
|
|
|
|
get_footer();
|