Merge pull request '清理 page-header 传参:主路径改 $args 契约' (#26) from worktree-bg-unified-single-home-mainline into main

Reviewed-on: CYL/wordpress-theme-aksrt#26
This commit is contained in:
kate522 committed 2026-07-09 23:01:42 +08:00
commit 21ad2cba11
4 files changed
+82 -61

No files matched your search

+6 -5
View File
@@ -53,11 +53,12 @@ if (function_exists('aksrt_archive_open_shell')) {
aksrt_render_admin_quick_link('post-list/list', __('列表样式设置', 'aksrt')); aksrt_render_admin_quick_link('post-list/list', __('列表样式设置', 'aksrt'));
} }
$admin_link = trim((string) ob_get_clean()); $admin_link = trim((string) ob_get_clean());
set_query_var('aksrt_ph_eyebrow', __('内容归档', 'aksrt')); get_template_part('templates/parts/page-header', null, [
set_query_var('aksrt_ph_title', get_the_archive_title()); 'eyebrow' => __('内容归档', 'aksrt'),
set_query_var('aksrt_ph_desc', $archive_summary); 'title' => get_the_archive_title(),
set_query_var('aksrt_ph_extra', $admin_link); 'desc' => $archive_summary,
get_template_part('templates/parts/page-header'); 'extra' => $admin_link,
]);
?> ?>
<?php <?php
+28 -26
View File
@@ -22,7 +22,7 @@ $show_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar
<div id="reading-progress-global" class="reading-progress-bar" role="progressbar" aria-label="<?php esc_attr_e('阅读进度', 'aksrt'); ?>" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"></div> <div id="reading-progress-global" class="reading-progress-bar" role="progressbar" aria-label="<?php esc_attr_e('阅读进度', 'aksrt'); ?>" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"></div>
<?php endif; ?> <?php endif; ?>
<main id="main-content" class="container page-content-<?php echo esc_attr($page_content_style); ?> page-id-<?php echo esc_attr((string) $page_id); ?>" tabindex="-1"> <main id="main-content" class="site-main container content-shell content-shell--page page-content-<?php echo esc_attr($page_content_style); ?> page-id-<?php echo esc_attr((string) $page_id); ?>" tabindex="-1">
<?php if (is_active_sidebar('page_top_fluid_' . $page_id)) : ?> <?php if (is_active_sidebar('page_top_fluid_' . $page_id)) : ?>
<div class="fluid-widget-wrap"> <div class="fluid-widget-wrap">
@@ -31,52 +31,54 @@ $show_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar
<?php endif; ?> <?php endif; ?>
<div class="content-wrap"> <div class="content-wrap">
<div class="content-layout<?php echo $show_sidebar ? "" : " no-sidebar"; ?>"> <div class="content-layout<?php echo $show_sidebar ? '' : ' content-layout--no-sidebar'; ?>">
<div class="content-layout__primary"> <div class="content-layout__primary">
<?php if (is_active_sidebar('page_top_content_' . $page_id)) : ?> <?php if (is_active_sidebar('page_top_content_' . $page_id)) : ?>
<?php dynamic_sidebar('page_top_content_' . $page_id); ?> <?php dynamic_sidebar('page_top_content_' . $page_id); ?>
<?php endif; ?> <?php endif; ?>
<?php <?php
while ( have_posts() ) : while (have_posts()) :
the_post(); the_post();
$page_meta_header_style = get_post_meta(get_the_ID(), 'page_header_style', true);
$ph_style_override = null;
if ($page_meta_header_style !== '' && in_array($page_meta_header_style, ['', '1', '2', '3', 'not'], true)) {
$ph_style_override = ($page_meta_header_style === 'not') ? '' : $page_meta_header_style;
}
$page_cover = (string) get_post_meta(get_the_ID(), 'page_header_cover_img', true);
$header_args = [
'title' => get_the_title(),
];
if ($ph_style_override !== null) {
$header_args['style'] = $ph_style_override;
}
if ($page_cover !== '') {
$header_args['cover'] = esc_url($page_cover);
}
?> ?>
<article <?php post_class('entry-page'); ?>> <article <?php post_class('entry-page'); ?>>
<?php <?php get_template_part('templates/parts/page-header', null, $header_args); ?>
$page_meta_header_style = get_post_meta(get_the_ID(), 'page_header_style', true);
if ($page_meta_header_style !== '' && in_array($page_meta_header_style, ['', '1', '2', '3', 'not'], true)) {
$ph_style_override = ($page_meta_header_style === 'not') ? '' : $page_meta_header_style;
set_query_var('aksrt_ph_style', $ph_style_override);
}
$page_cover = get_post_meta(get_the_ID(), 'page_header_cover_img', true);
if (!empty($page_cover)) {
set_query_var('aksrt_ph_cover', esc_url($page_cover));
}
set_query_var('aksrt_ph_title', get_the_title());
get_template_part('templates/parts/page-header');
?>
<?php if ( has_post_thumbnail() ) : ?> <?php if (has_post_thumbnail()) : ?>
<figure class="entry-thumb"> <figure class="entry-thumb">
<?php the_post_thumbnail( 'large' ); ?> <?php the_post_thumbnail('large'); ?>
</figure> </figure>
<?php endif; ?> <?php endif; ?>
<div class="entry-content" data-aksrt-lightbox="<?php echo !empty($page_settings['lightbox']) ? '1' : '0'; ?>"> <div class="entry-content" data-aksrt-lightbox="<?php echo !empty($page_settings['lightbox']) ? '1' : '0'; ?>">
<?php the_content(); ?> <?php the_content(); ?>
<?php <?php
wp_link_pages( wp_link_pages([
array( 'before' => '<nav class="page-links"><span class="page-links-title">' . esc_html__('分页:', 'aksrt') . '</span>',
'before' => '<nav class="page-links"><span class="page-links-title">' . esc_html__( '分页:', 'aksrt' ) . '</span>', 'after' => '</nav>',
'after' => '</nav>', ]);
)
);
?> ?>
</div> </div>
</article> </article>
<?php <?php
if ( comments_open() || get_comments_number() ) { if (comments_open() || get_comments_number()) {
echo '<div class="theme-box box-body radius8 main-shadow comments-card">'; echo '<div class="theme-box box-body radius8 main-shadow comments-card">';
comments_template(); comments_template();
echo '</div>'; echo '</div>';
@@ -92,7 +94,7 @@ $show_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar
<?php if ($show_sidebar) : ?> <?php if ($show_sidebar) : ?>
<?php get_sidebar(); ?> <?php get_sidebar(); ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
+6 -5
View File
@@ -145,11 +145,12 @@ if (function_exists('aksrt_archive_open_shell')) {
aksrt_render_admin_quick_link('page-display/other', __('搜索页设置', 'aksrt')); aksrt_render_admin_quick_link('page-display/other', __('搜索页设置', 'aksrt'));
} }
$admin_link = trim((string) ob_get_clean()); $admin_link = trim((string) ob_get_clean());
set_query_var('aksrt_ph_eyebrow', __('站内搜索', 'aksrt')); get_template_part('templates/parts/page-header', null, [
set_query_var('aksrt_ph_title', $search_title); 'eyebrow' => __('站内搜索', 'aksrt'),
set_query_var('aksrt_ph_desc', $search_desc); 'title' => $search_title,
set_query_var('aksrt_ph_extra', $admin_link); 'desc' => $search_desc,
get_template_part('templates/parts/page-header'); 'extra' => $admin_link,
]);
?> ?>
<section class="content-stream content-stream--search content-stream--archive" data-page-kind="search" data-render-mode="<?php echo esc_attr((string) $render_config['mode']); ?>" data-card-style="<?php echo esc_attr((string) $render_config['card_style']); ?>"> <section class="content-stream content-stream--search content-stream--archive" data-page-kind="search" data-render-mode="<?php echo esc_attr((string) $render_config['mode']); ?>" data-card-style="<?php echo esc_attr((string) $render_config['card_style']); ?>">
+42 -25
View File
@@ -2,49 +2,66 @@
/** /**
* Reusable Page Header Template Part. * Reusable Page Header Template Part.
* *
* Renders a unified page header for archive / search / page templates. * Contract: get_template_part(..., null, $args)
* Style is driven by the global setting `page_header_style` with optional * Prefer explicit $args over ambient query vars.
* per-page post-meta override (`page_header_style`).
* *
* Query vars consumed (set via set_query_var before calling get_template_part): * Args:
* aksrt_ph_style – override style ('' | '1' | '2' | '3'), defaults to global setting * style – '' | '1' | '2' | '3' | 'not'
* aksrt_ph_eyebrow – eyebrow label text * eyebrow – eyebrow label text
* aksrt_ph_title – title HTML (already escaped by caller) * title – title HTML (caller escapes)
* aksrt_ph_desc – description text * desc – description text
* aksrt_ph_cover – cover image URL override * cover – cover image URL override
* aksrt_ph_extra – extra HTML appended inside the body area (e.g. admin quick-links) * extra – extra HTML (caller escapes)
* *
* @package AKSRT * @package AKSRT
*/ */
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
// Resolve style: explicit query var > global setting. $args = is_array($args ?? null) ? $args : [];
$ph_style = get_query_var('aksrt_ph_style', null);
// Resolve style: explicit args > residual query var > global setting.
$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')
: '1'; : '1';
} }
if ($ph_style === 'not') {
$ph_style = '';
}
// '' means "don't show header" // '' means "don't show header"
if ($ph_style === '') { if ($ph_style === '') {
return; return;
} }
$ph_eyebrow = get_query_var('aksrt_ph_eyebrow', ''); $ph_eyebrow = array_key_exists('eyebrow', $args)
$ph_title = get_query_var('aksrt_ph_title', ''); ? (string) $args['eyebrow']
$ph_desc = get_query_var('aksrt_ph_desc', ''); : (string) get_query_var('aksrt_ph_eyebrow', '');
$ph_extra = get_query_var('aksrt_ph_extra', ''); $ph_title = array_key_exists('title', $args)
? (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 > global setting > post thumbnail. // Cover image: explicit args > residual query var > global setting > post thumbnail.
$ph_cover = get_query_var('aksrt_ph_cover', ''); $ph_cover = array_key_exists('cover', $args)
if (empty($ph_cover) && class_exists('AKSRT_Settings')) { ? (string) $args['cover']
: (string) get_query_var('aksrt_ph_cover', '');
if ($ph_cover === '' && class_exists('AKSRT_Settings')) {
$other = AKSRT_Settings::get_other_page_settings(); $other = AKSRT_Settings::get_other_page_settings();
$ph_cover = $other['header_cover_img'] ?? ''; $ph_cover = (string) ($other['header_cover_img'] ?? '');
} }
if (empty($ph_cover) && has_post_thumbnail()) { if ($ph_cover === '' && has_post_thumbnail()) {
$ph_cover = get_the_post_thumbnail_url(get_the_ID(), 'full'); $ph_cover = (string) get_the_post_thumbnail_url(get_the_ID(), 'full');
} }
// Map style value to CSS modifier class. // Map style value to CSS modifier class.
@@ -57,13 +74,13 @@ if ($ph_style === '2') {
// Cover inline style (for cover style). // Cover inline style (for cover style).
$cover_style = ''; $cover_style = '';
if ($ph_style === '3' && !empty($ph_cover)) { if ($ph_style === '3' && $ph_cover !== '') {
$cover_style = ' style="background-image:url(\'' . esc_url($ph_cover) . '\')"'; $cover_style = ' style="background-image:url(\'' . esc_url($ph_cover) . '\')"';
} }
?> ?>
<header class="page-header term-page-header <?php echo esc_attr($style_class); ?>"> <header class="page-header term-page-header <?php echo esc_attr($style_class); ?>">
<?php if ($ph_style === '3' && !empty($ph_cover)) : ?> <?php if ($ph_style === '3' && $ph_cover !== '') : ?>
<div class="term-page-header__cover-bg"<?php echo $cover_style; /* phpcs:ignore -- escaped above */ ?>> <div class="term-page-header__cover-bg"<?php echo $cover_style; /* phpcs:ignore -- escaped above */ ?>>
<div class="term-page-header__cover-overlay"></div> <div class="term-page-header__cover-overlay"></div>
</div> </div>
@@ -87,7 +104,7 @@ if ($ph_style === '3' && !empty($ph_cover)) {
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php if ($ph_style === '2' && !empty($ph_cover)) : ?> <?php if ($ph_style === '2' && $ph_cover !== '') : ?>
<div class="term-page-header__cover"<?php echo $cover_style; /* phpcs:ignore -- escaped above */ ?>></div> <div class="term-page-header__cover"<?php echo $cover_style; /* phpcs:ignore -- escaped above */ ?>></div>
<?php endif; ?> <?php endif; ?>
</header> </header>