专用页对齐 content-shell,并删 page-header query-var 回退

archives/friends/newposts/posts-navs/categories 统一壳层与 page-header 契约,
主路径不再保留 aksrt_ph_* ambient 传参。
This commit is contained in:
2026-07-09 23:05:06 +08:00
parent 9fd0735e97
commit 8849540fda
6 changed files with 228 additions and 210 deletions
+56 -49
View File
@@ -12,57 +12,64 @@ defined('ABSPATH') || exit;
get_header(); get_header();
global $wpdb; global $wpdb;
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--page page-content-default',
'has_sidebar' => false,
'page_kind' => 'archives',
]);
}
?> ?>
<div class="content-main content-main--page content-main--archives">
<?php
get_template_part('templates/parts/page-header', null, [
'title' => esc_html__('文章归档', 'aksrt'),
]);
?>
<main id="main-content" class="container page-content-default" tabindex="-1"> <div class="aksrt-archives">
<header class="page-header"> <?php
<h1 class="entry-title"><?php esc_html_e('文章归档', 'aksrt'); ?></h1> $years = $wpdb->get_results(
</header> "SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, COUNT(*) AS count
FROM {$wpdb->posts}
<div class="content-wrap"> WHERE post_type = 'post' AND post_status = 'publish'
<div class="content-layout content-layout--no-sidebar"> GROUP BY YEAR(post_date), MONTH(post_date)
<div class="content-layout__primary"> ORDER BY year DESC, month DESC"
<div class="aksrt-archives container"> ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
<?php
$years = $wpdb->get_results(
"SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, COUNT(*) AS count
FROM {$wpdb->posts}
WHERE post_type = 'post' AND post_status = 'publish'
GROUP BY YEAR(post_date), MONTH(post_date)
ORDER BY year DESC, month DESC"
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$current_year = 0;
foreach ($years as $row) :
if ((int) $row->year !== $current_year) :
$current_year = (int) $row->year;
?>
<h2 class="aksrt-archives__year"><?php echo esc_html($current_year); ?></h2>
<?php endif; ?>
<h3 class="aksrt-archives__month">
<?php echo esc_html(sprintf('%d 月 (%d 篇)', (int) $row->month, (int) $row->count)); ?>
</h3>
<ul class="aksrt-archives__list">
<?php
$month_posts = get_posts([
'year' => (int) $row->year,
'monthnum' => (int) $row->month,
'posts_per_page' => -1,
'post_status' => 'publish',
]);
foreach ($month_posts as $mp) :
?>
<li class="aksrt-archives__item">
<span class="aksrt-archives__date"><?php echo esc_html(get_the_date('m-d', $mp)); ?></span>
<a href="<?php echo esc_url(get_permalink($mp->ID)); ?>" class="aksrt-archives__link"><?php echo esc_html($mp->post_title); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
</div>
</div>
</main>
$current_year = 0;
foreach ($years as $row) :
if ((int) $row->year !== $current_year) :
$current_year = (int) $row->year;
?>
<h2 class="aksrt-archives__year"><?php echo esc_html((string) $current_year); ?></h2>
<?php endif; ?>
<h3 class="aksrt-archives__month">
<?php echo esc_html(sprintf('%d 月 (%d 篇)', (int) $row->month, (int) $row->count)); ?>
</h3>
<ul class="aksrt-archives__list">
<?php
$month_posts = get_posts([
'year' => (int) $row->year,
'monthnum' => (int) $row->month,
'posts_per_page' => -1,
'post_status' => 'publish',
]);
foreach ($month_posts as $mp) :
?>
<li class="aksrt-archives__item">
<span class="aksrt-archives__date"><?php echo esc_html(get_the_date('m-d', $mp)); ?></span>
<a href="<?php echo esc_url(get_permalink($mp->ID)); ?>" class="aksrt-archives__link"><?php echo esc_html($mp->post_title); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
</div>
<?php <?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell(['has_sidebar' => false]);
}
get_footer(); get_footer();
+29 -20
View File
@@ -46,26 +46,31 @@ if ($page_title === '') {
} }
?> ?>
<main id="main-content" class="site-main content-shell" tabindex="-1"> <?php
<?php if (function_exists('aksrt_breadcrumbs')) { if (function_exists('aksrt_archive_open_shell')) {
aksrt_breadcrumbs(); aksrt_archive_open_shell([
} ?> 'main_class' => 'site-main container content-shell content-shell--page',
'has_sidebar' => false,
'page_kind' => 'categories',
]);
}
?>
<div class="content-main content-main--page content-main--categories">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<?php
$cats_meta = sprintf(
/* translators: 1: total category count, 2: total published post count */
esc_html__('共 %1$d 个分类 · 共 %2$d 篇文章', 'aksrt'),
$total_cats,
$total_posts
);
get_template_part('templates/parts/page-header', null, [
'title' => esc_html($page_title),
'desc' => $cats_meta,
]);
?>
<header class="page-header aksrt-cats-header"> <?php if (!empty($top_level)) : ?>
<h1 class="entry-title"><?php echo esc_html($page_title); ?></h1>
<p class="aksrt-cats-header__meta">
<?php
printf(
/* translators: 1: total category count, 2: total published post count */
esc_html__('共 %1$d 个分类 · 共 %2$d 篇文章', 'aksrt'),
$total_cats,
$total_posts
);
?>
</p>
</header>
<?php if (!empty($top_level)) : ?>
<section class="aksrt-cats-grid" aria-label="<?php esc_attr_e('分类列表', 'aksrt'); ?>"> <section class="aksrt-cats-grid" aria-label="<?php esc_attr_e('分类列表', 'aksrt'); ?>">
<?php foreach ($top_level as $cat) : <?php foreach ($top_level as $cat) :
$cat_id = (int) $cat->term_id; $cat_id = (int) $cat->term_id;
@@ -124,7 +129,11 @@ if ($page_title === '') {
<?php esc_html_e('返回首页', 'aksrt'); ?> <?php esc_html_e('返回首页', 'aksrt'); ?>
</a> </a>
</p> </p>
</main>
</div>
<?php <?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell(['has_sidebar' => false]);
}
get_footer(); get_footer();
+47 -42
View File
@@ -11,51 +11,56 @@ defined('ABSPATH') || exit;
get_header(); get_header();
$links = function_exists('aksrt_get_friend_links') ? aksrt_get_friend_links() : []; $links = function_exists('aksrt_get_friend_links') ? aksrt_get_friend_links() : [];
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--page page-content-default',
'has_sidebar' => false,
'page_kind' => 'friends',
]);
}
?> ?>
<div class="content-main content-main--page content-main--friends">
<?php
get_template_part('templates/parts/page-header', null, [
'title' => esc_html__('友情链接', 'aksrt'),
'desc' => __('与这些优秀的站点交换友链', 'aksrt'),
]);
?>
<main id="main-content" class="container page-content-default" tabindex="-1"> <?php if (!empty($links)) : ?>
<header class="page-header"> <div class="friends-grid">
<h1 class="entry-title"><?php esc_html_e('友情链接', 'aksrt'); ?></h1> <?php foreach ($links as $link) : ?>
<p><?php esc_html_e('与这些优秀的站点交换友链', 'aksrt'); ?></p> <a class="friend-card" href="<?php echo esc_url($link['url'] ?? '#'); ?>" target="_blank" rel="noopener noreferrer">
</header> <?php
$logo = $link['logo'] ?? '';
if ($logo) {
echo '<img class="friend-card__avatar" src="' . esc_url($logo) . '" alt="">';
} else {
$initial = function_exists('mb_substr') ? mb_substr((string) ($link['name'] ?? 'A'), 0, 1, 'UTF-8') : substr((string) ($link['name'] ?? 'A'), 0, 1);
echo '<div class="friend-card__avatar" style="display:flex;align-items:center;justify-content:center;font-weight:800;color:var(--color-primary);font-family:var(--font-heading);">' . esc_html($initial) . '</div>';
}
?>
<div class="friend-card__info">
<h3 class="friend-card__name"><?php echo esc_html($link['name'] ?? ''); ?></h3>
<p class="friend-card__desc"><?php echo esc_html($link['description'] ?? ''); ?></p>
</div>
</a>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="no-results content-stream__empty">
<p><?php esc_html_e('暂无友链,请在主题后台添加。', 'aksrt'); ?></p>
</div>
<?php endif; ?>
<div class="content-wrap"> <p class="text-center" style="margin-top:32px;">
<div class="content-layout content-layout--no-sidebar"> <a class="btn-outline" href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('返回首页', 'aksrt'); ?></a>
<div class="content-layout__primary"> </p>
<?php if (! empty($links)) : ?>
<div class="friends-grid">
<?php foreach ($links as $link) : ?>
<a class="friend-card" href="<?php echo esc_url($link['url'] ?? '#'); ?>" target="_blank" rel="noopener noreferrer">
<?php
$logo = $link['logo'] ?? '';
if ($logo) {
echo '<img class="friend-card__avatar" src="' . esc_url($logo) . '" alt="">';
} else {
$initial = function_exists('mb_substr') ? mb_substr((string) ($link['name'] ?? 'A'), 0, 1, 'UTF-8') : substr((string) ($link['name'] ?? 'A'), 0, 1);
echo '<div class="friend-card__avatar" style="display:flex;align-items:center;justify-content:center;font-weight:800;color:var(--color-primary);font-family:var(--font-heading);">' . esc_html($initial) . '</div>';
}
?>
<div class="friend-card__info">
<h3 class="friend-card__name"><?php echo esc_html($link['name'] ?? ''); ?></h3>
<p class="friend-card__desc"><?php echo esc_html($link['description'] ?? ''); ?></p>
</div> </div>
</a>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="no-results">
<p><?php esc_html_e('暂无友链,请在主题后台添加。', 'aksrt'); ?></p>
</div>
<?php endif; ?>
<p style="text-align:center;margin-top:32px;">
<a class="btn-outline" href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('返回首页', 'aksrt'); ?></a>
</p>
</div>
</div>
</div>
</main>
<?php <?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell(['has_sidebar' => false]);
}
get_footer(); get_footer();
+44 -39
View File
@@ -14,7 +14,6 @@ get_header();
$paged = max(1, (int) get_query_var('paged')); $paged = max(1, (int) get_query_var('paged'));
$per_page = 20; $per_page = 20;
$query = new WP_Query([ $query = new WP_Query([
'post_type' => 'post', 'post_type' => 'post',
'post_status' => 'publish', 'post_status' => 'publish',
@@ -23,45 +22,51 @@ $query = new WP_Query([
'orderby' => 'date', 'orderby' => 'date',
'order' => 'DESC', 'order' => 'DESC',
]); ]);
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--page page-content-default',
'has_sidebar' => false,
'page_kind' => 'newposts',
]);
}
?> ?>
<div class="content-main content-main--page content-main--newposts">
<?php
get_template_part('templates/parts/page-header', null, [
'title' => esc_html(get_the_title() ?: __('最新文章', 'aksrt')),
]);
?>
<main id="main-content" class="container page-content-default" tabindex="-1"> <div class="aksrt-newposts">
<header class="page-header"> <?php if ($query->have_posts()) : ?>
<h1 class="entry-title"><?php echo esc_html(get_the_title() ?: __('最新文章', 'aksrt')); ?></h1> <div class="aksrt-newposts__list">
</header> <?php while ($query->have_posts()) : $query->the_post(); ?>
<article class="aksrt-newposts__item">
<div class="content-wrap"> <span class="aksrt-newposts__date"><?php echo esc_html(get_the_date()); ?></span>
<div class="content-layout content-layout--no-sidebar"> <h3 class="aksrt-newposts__title">
<div class="content-layout__primary"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="aksrt-newposts container"> </h3>
<?php if ($query->have_posts()) : ?> <p class="aksrt-newposts__excerpt"><?php echo esc_html(wp_trim_words(get_the_excerpt(), 30)); ?></p>
<div class="aksrt-newposts__list"> </article>
<?php while ($query->have_posts()) : $query->the_post(); ?> <?php endwhile; ?>
<article class="aksrt-newposts__item"> </div>
<span class="aksrt-newposts__date"><?php echo esc_html(get_the_date()); ?></span> <?php
<h3 class="aksrt-newposts__title"> if (function_exists('aksrt_render_pagination')) {
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> aksrt_render_pagination($query);
</h3> } else {
<p class="aksrt-newposts__excerpt"><?php echo esc_html(wp_trim_words(get_the_excerpt(), 30)); ?></p> echo '<div class="aksrt-pagination">' . paginate_links(['total' => $query->max_num_pages]) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
</article> }
<?php endwhile; ?> wp_reset_postdata();
</div> ?>
<?php <?php else : ?>
if (function_exists('aksrt_render_pagination')) { <p class="aksrt-newposts__empty content-stream__empty"><?php esc_html_e('暂无文章。', 'aksrt'); ?></p>
aksrt_render_pagination($query); <?php endif; ?>
} else { </div>
echo '<div class="aksrt-pagination">' . paginate_links(['total' => $query->max_num_pages]) . '</div>'; </div>
}
?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p class="aksrt-newposts__empty"><?php esc_html_e('暂无文章。', 'aksrt'); ?></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<?php <?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell(['has_sidebar' => false]);
}
get_footer(); get_footer();
+45 -39
View File
@@ -13,47 +13,53 @@ defined('ABSPATH') || exit;
get_header(); get_header();
$categories = get_categories(['hide_empty' => true, 'orderby' => 'count', 'order' => 'DESC', 'number' => 20]); $categories = get_categories(['hide_empty' => true, 'orderby' => 'count', 'order' => 'DESC', 'number' => 20]);
$tags = get_tags(['hide_empty' => true, 'orderby' => 'count', 'order' => 'DESC', 'number' => 40]); $tags = get_tags(['hide_empty' => true, 'orderby' => 'count', 'order' => 'DESC', 'number' => 40]);
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container content-shell content-shell--page page-content-default',
'has_sidebar' => false,
'page_kind' => 'posts-navs',
]);
}
?> ?>
<div class="content-main content-main--page content-main--posts-navs">
<?php
get_template_part('templates/parts/page-header', null, [
'title' => esc_html(get_the_title() ?: __('文章导航', 'aksrt')),
]);
?>
<main id="main-content" class="container page-content-default" tabindex="-1"> <div class="aksrt-posts-navs">
<header class="page-header"> <?php if (!empty($categories)) : ?>
<h1 class="entry-title"><?php echo esc_html(get_the_title() ?: __('文章导航', 'aksrt')); ?></h1> <section class="aksrt-posts-navs__section">
</header> <h2 class="aksrt-posts-navs__heading"><?php esc_html_e('热门分类', 'aksrt'); ?></h2>
<div class="aksrt-posts-navs__cats">
<div class="content-wrap"> <?php foreach ($categories as $cat) : ?>
<div class="content-layout content-layout--no-sidebar"> <a href="<?php echo esc_url(get_category_link($cat->term_id)); ?>" class="aksrt-posts-navs__cat-chip">
<div class="content-layout__primary"> <span class="aksrt-posts-navs__cat-name"><?php echo esc_html($cat->name); ?></span>
<div class="aksrt-posts-navs container"> <span class="aksrt-posts-navs__cat-count"><?php echo esc_html((string) $cat->count); ?></span>
<?php if (!empty($categories)) : ?> </a>
<section class="aksrt-posts-navs__section"> <?php endforeach; ?>
<h2 class="aksrt-posts-navs__heading"><?php esc_html_e('热门分类', 'aksrt'); ?></h2> </div>
<div class="aksrt-posts-navs__cats"> </section>
<?php foreach ($categories as $cat) : ?> <?php endif; ?>
<a href="<?php echo esc_url(get_category_link($cat->term_id)); ?>" class="aksrt-posts-navs__cat-chip">
<span class="aksrt-posts-navs__cat-name"><?php echo esc_html($cat->name); ?></span>
<span class="aksrt-posts-navs__cat-count"><?php echo esc_html($cat->count); ?></span>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if (!empty($tags)) : ?>
<section class="aksrt-posts-navs__section">
<h2 class="aksrt-posts-navs__heading"><?php esc_html_e('热门标签', 'aksrt'); ?></h2>
<div class="aksrt-posts-navs__tags">
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>" class="aksrt-posts-navs__tag"><?php echo esc_html($tag->name); ?></a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<?php if (!empty($tags)) : ?>
<section class="aksrt-posts-navs__section">
<h2 class="aksrt-posts-navs__heading"><?php esc_html_e('热门标签', 'aksrt'); ?></h2>
<div class="aksrt-posts-navs__tags">
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>" class="aksrt-posts-navs__tag"><?php echo esc_html($tag->name); ?></a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
</div>
</div>
<?php <?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell(['has_sidebar' => false]);
}
get_footer(); get_footer();
+7 -21
View File
@@ -3,7 +3,6 @@
* Reusable Page Header Template Part. * Reusable Page Header Template Part.
* *
* Contract: get_template_part(..., null, $args) * Contract: get_template_part(..., null, $args)
* Prefer explicit $args over ambient query vars.
* *
* Args: * Args:
* style – '' | '1' | '2' | '3' | 'not' * style – '' | '1' | '2' | '3' | 'not'
@@ -20,11 +19,8 @@ defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : []; $args = is_array($args ?? null) ? $args : [];
// Resolve style: explicit args > residual query var > global setting. // Resolve style: explicit args > global setting.
$ph_style = array_key_exists('style', $args) ? $args['style'] : null; $ph_style = array_key_exists('style', $args) ? $args['style'] : null;
if ($ph_style === null) {
$ph_style = get_query_var('aksrt_ph_style', null);
}
if ($ph_style === null) { if ($ph_style === null) {
$ph_style = class_exists('AKSRT_Settings') $ph_style = class_exists('AKSRT_Settings')
? (AKSRT_Settings::get_other_page_settings()['header_style'] ?? '1') ? (AKSRT_Settings::get_other_page_settings()['header_style'] ?? '1')
@@ -39,23 +35,13 @@ if ($ph_style === '') {
return; return;
} }
$ph_eyebrow = array_key_exists('eyebrow', $args) $ph_eyebrow = (string) ($args['eyebrow'] ?? '');
? (string) $args['eyebrow'] $ph_title = (string) ($args['title'] ?? '');
: (string) get_query_var('aksrt_ph_eyebrow', ''); $ph_desc = (string) ($args['desc'] ?? '');
$ph_title = array_key_exists('title', $args) $ph_extra = (string) ($args['extra'] ?? '');
? (string) $args['title']
: (string) get_query_var('aksrt_ph_title', '');
$ph_desc = array_key_exists('desc', $args)
? (string) $args['desc']
: (string) get_query_var('aksrt_ph_desc', '');
$ph_extra = array_key_exists('extra', $args)
? (string) $args['extra']
: (string) get_query_var('aksrt_ph_extra', '');
// Cover image: explicit args > residual query var > global setting > post thumbnail. // Cover image: explicit args > global setting > post thumbnail.
$ph_cover = array_key_exists('cover', $args) $ph_cover = (string) ($args['cover'] ?? '');
? (string) $args['cover']
: (string) get_query_var('aksrt_ph_cover', '');
if ($ph_cover === '' && class_exists('AKSRT_Settings')) { if ($ph_cover === '' && class_exists('AKSRT_Settings')) {
$other = AKSRT_Settings::get_other_page_settings(); $other = AKSRT_Settings::get_other_page_settings();
$ph_cover = (string) ($other['header_cover_img'] ?? ''); $ph_cover = (string) ($other['header_cover_img'] ?? '');