feat(frontend): align single post page 1:1 with Zibll
Restore Zibll float dual-column shell, fix single settings DTO key mapping, reorder article footer/actions, and match author bar, prev/next, title/body typography, and limit-height expand UX.
This commit is contained in:
1 parent
a651bd6d2d
commit
5ae1a9ad93
12 files changed
+626
-218
No files matched your search
@@ -228,16 +228,40 @@ class AKSRT_Settings_Post_Display {
|
||||
public static function get_post_page_settings(): array {
|
||||
$settings = AKSRT_Settings::get_all();
|
||||
|
||||
// Canonical render keys (used by aksrt_single_*). Legacy *_s aliases kept for older callers.
|
||||
$breadcrumbs = !isset($settings['breadcrumbs_single_s']) || !empty($settings['breadcrumbs_single_s']);
|
||||
$breadcrumbs_home = sanitize_text_field((string) ($settings['breadcrumbs_home_text'] ?? '首页'));
|
||||
$prevnext = !isset($settings['post_prevnext_s']) || !empty($settings['post_prevnext_s']);
|
||||
$authordesc = !isset($settings['post_authordesc_s']) || !empty($settings['post_authordesc_s']);
|
||||
$hide_time = !empty($settings['post_single_hide_time_s']);
|
||||
$share_enabled = !isset($settings['share_s']) || !empty($settings['share_s']);
|
||||
$rewards_enabled = !empty($settings['post_rewards_enabled']) || !empty($settings['post_rewards_s']);
|
||||
$rewards_image = (string) ($settings['post_rewards_image'] ?? $settings['post_rewards_qrcode'] ?? '');
|
||||
$rewards_text = sanitize_text_field((string) ($settings['post_rewards_text'] ?? ''));
|
||||
$rewards_btn_text = sanitize_text_field((string) ($settings['post_rewards_btn_text'] ?? '赞赏'));
|
||||
$maxheight_enabled = !empty($settings['article_maxheight_kg']) || !empty($settings['post_article_maxheight_kg']);
|
||||
$maxheight = max(0, (int) ($settings['article_maxheight'] ?? $settings['post_article_maxheight'] ?? 1000));
|
||||
if ($maxheight <= 0) {
|
||||
$maxheight = 1000;
|
||||
}
|
||||
|
||||
return [
|
||||
'toc_enabled' => !isset($settings['post_toc_enabled']) || !empty($settings['post_toc_enabled']),
|
||||
'toc_depth' => max(1, min(6, (int) ($settings['post_toc_depth'] ?? 3))),
|
||||
'article_nav_mobile_nav_s' => !isset($settings['article_nav_mobile_nav_s']) || !empty($settings['article_nav_mobile_nav_s']),
|
||||
'reading_progress' => !isset($settings['post_reading_progress']) || !empty($settings['post_reading_progress']),
|
||||
'breadcrumbs_single_s' => !isset($settings['breadcrumbs_single_s']) || !empty($settings['breadcrumbs_single_s']),
|
||||
'breadcrumbs_home_text' => sanitize_text_field((string) ($settings['breadcrumbs_home_text'] ?? '首页')),
|
||||
'prevnext_s' => !isset($settings['post_prevnext_s']) || !empty($settings['post_prevnext_s']),
|
||||
'authordesc_s' => !isset($settings['post_authordesc_s']) || !empty($settings['post_authordesc_s']),
|
||||
'single_hide_time_s' => !empty($settings['post_single_hide_time_s']),
|
||||
// Canonical + legacy breadcrumbs.
|
||||
'breadcrumbs' => $breadcrumbs,
|
||||
'breadcrumbs_home' => $breadcrumbs_home,
|
||||
'breadcrumbs_single_s' => $breadcrumbs,
|
||||
'breadcrumbs_home_text' => $breadcrumbs_home,
|
||||
// Canonical + legacy prev/next / author / time.
|
||||
'prevnext' => $prevnext,
|
||||
'prevnext_s' => $prevnext,
|
||||
'authordesc' => $authordesc,
|
||||
'authordesc_s' => $authordesc,
|
||||
'hide_time' => $hide_time,
|
||||
'single_hide_time_s' => $hide_time,
|
||||
'article_image_cover' => !isset($settings['post_article_image_cover']) || !empty($settings['post_article_image_cover']),
|
||||
'article_image_cover_scale'=> max(10, min(100, (int) ($settings['post_article_image_cover_scale'] ?? 35))),
|
||||
'article_slide_cover' => !isset($settings['post_article_slide_cover']) || !empty($settings['post_article_slide_cover']),
|
||||
@@ -256,7 +280,17 @@ class AKSRT_Settings_Post_Display {
|
||||
'related_title' => sanitize_text_field((string) ($settings['post_related_title'] ?? '相关推荐')),
|
||||
'like_enabled' => !isset($settings['post_like_enabled']) || !empty($settings['post_like_enabled']),
|
||||
'favorite_enabled' => !isset($settings['post_favorite_enabled']) || !empty($settings['post_favorite_enabled']),
|
||||
'share_s' => !isset($settings['share_s']) || !empty($settings['share_s']),
|
||||
// Canonical + legacy share.
|
||||
'share_enabled' => $share_enabled,
|
||||
'share_s' => $share_enabled,
|
||||
// Rewards (Zibll post_rewards_s).
|
||||
'rewards_enabled' => $rewards_enabled,
|
||||
'rewards_image' => $rewards_image,
|
||||
'rewards_text' => $rewards_text,
|
||||
'rewards_btn_text' => $rewards_btn_text !== '' ? $rewards_btn_text : '赞赏',
|
||||
// Content max height (Zibll article_maxheight_kg / article_maxheight).
|
||||
'maxheight_enabled' => $maxheight_enabled,
|
||||
'maxheight' => $maxheight,
|
||||
'copyright_enabled' => !isset($settings['post_copyright_enabled']) || !empty($settings['post_copyright_enabled']),
|
||||
'copyright_text' => (string) ($settings['post_copyright_text'] ?? ''),
|
||||
'button_toptext' => sanitize_text_field((string) ($settings['post_button_toptext'] ?? '喜欢就支持一下吧')),
|
||||
@@ -269,6 +303,8 @@ class AKSRT_Settings_Post_Display {
|
||||
'default_views_max' => max(1, min(9999, (int) ($settings['post_default_views_max'] ?? 50))),
|
||||
'default_likes_min' => max(0, min(9999, (int) ($settings['post_default_likes_min'] ?? 5))),
|
||||
'default_likes_max' => max(1, min(9999, (int) ($settings['post_default_likes_max'] ?? 15))),
|
||||
'word_count_enabled' => !isset($settings['post_word_count_enabled']) || !empty($settings['post_word_count_enabled']),
|
||||
'reading_time_enabled' => !isset($settings['post_reading_time_enabled']) || !empty($settings['post_reading_time_enabled']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,17 @@ if (!function_exists('aksrt_resolve_single_post_display_settings')) :
|
||||
'like_enabled' => true,
|
||||
'favorite_enabled' => true,
|
||||
'share_enabled' => true,
|
||||
'breadcrumbs' => true,
|
||||
'breadcrumbs_home' => '首页',
|
||||
'prevnext' => true,
|
||||
'authordesc' => true,
|
||||
'hide_time' => false,
|
||||
'rewards_enabled' => false,
|
||||
'rewards_image' => '',
|
||||
'rewards_text' => '',
|
||||
'rewards_btn_text' => '赞赏',
|
||||
'maxheight_enabled' => false,
|
||||
'maxheight' => 1000,
|
||||
'copyright_enabled' => true,
|
||||
'copyright_text' => '',
|
||||
'front_content' => '',
|
||||
@@ -205,6 +216,26 @@ if (!function_exists('aksrt_resolve_single_post_display_settings')) :
|
||||
'reading_time_enabled' => true,
|
||||
];
|
||||
|
||||
// Normalize legacy aliases → canonical render keys (idempotent).
|
||||
if (!array_key_exists('share_enabled', $settings) && array_key_exists('share_s', $settings)) {
|
||||
$settings['share_enabled'] = !empty($settings['share_s']);
|
||||
}
|
||||
if (!array_key_exists('hide_time', $settings) && array_key_exists('single_hide_time_s', $settings)) {
|
||||
$settings['hide_time'] = !empty($settings['single_hide_time_s']);
|
||||
}
|
||||
if (!array_key_exists('breadcrumbs', $settings) && array_key_exists('breadcrumbs_single_s', $settings)) {
|
||||
$settings['breadcrumbs'] = !empty($settings['breadcrumbs_single_s']);
|
||||
}
|
||||
if (!array_key_exists('breadcrumbs_home', $settings) && array_key_exists('breadcrumbs_home_text', $settings)) {
|
||||
$settings['breadcrumbs_home'] = (string) $settings['breadcrumbs_home_text'];
|
||||
}
|
||||
if (!array_key_exists('prevnext', $settings) && array_key_exists('prevnext_s', $settings)) {
|
||||
$settings['prevnext'] = !empty($settings['prevnext_s']);
|
||||
}
|
||||
if (!array_key_exists('authordesc', $settings) && array_key_exists('authordesc_s', $settings)) {
|
||||
$settings['authordesc'] = !empty($settings['authordesc_s']);
|
||||
}
|
||||
|
||||
$meta = class_exists('AKSRT_Post_Meta_Box') ? AKSRT_Post_Meta_Box::get_meta($post->ID) : [];
|
||||
if (($meta['show_toc'] ?? '') !== '') {
|
||||
$settings['toc_enabled'] = $meta['show_toc'] === '1';
|
||||
@@ -231,11 +262,14 @@ if (!function_exists('aksrt_resolve_single_post_display_settings')) :
|
||||
$settings['related_count'] = max(1, min(20, (int) $meta['related_count']));
|
||||
}
|
||||
|
||||
// Per-post maxheight override (Zibll article_maxheight_xz).
|
||||
// Per-post maxheight override (Zibll article_maxheight_xz). Global may already set maxheight_enabled.
|
||||
$meta_maxheight = (int) ($meta['maxheight'] ?? 0);
|
||||
if ($meta_maxheight > 0) {
|
||||
$settings['maxheight_enabled'] = true;
|
||||
$settings['maxheight'] = $meta_maxheight;
|
||||
} elseif (empty($settings['maxheight_enabled'])) {
|
||||
$settings['maxheight_enabled'] = false;
|
||||
$settings['maxheight'] = max(0, (int) ($settings['maxheight'] ?? 0));
|
||||
}
|
||||
|
||||
$cover_mode = (string) ($meta['header_image_mode'] ?? '');
|
||||
|
||||
@@ -92,7 +92,7 @@ if (!function_exists('aksrt_single_build_context')) :
|
||||
$breadcrumbs_html = '';
|
||||
if (!empty($settings['breadcrumbs']) && function_exists('aksrt_breadcrumbs')) {
|
||||
ob_start();
|
||||
aksrt_breadcrumbs($settings['breadcrumbs_home'] ?? '');
|
||||
aksrt_breadcrumbs($settings['breadcrumbs_home'] ?? ($settings['breadcrumbs_home_text'] ?? ''));
|
||||
$breadcrumbs_html = trim((string) ob_get_clean());
|
||||
}
|
||||
|
||||
@@ -508,13 +508,12 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_prevnext')) :
|
||||
/**
|
||||
* Previous / next navigation.
|
||||
* Previous / next navigation (Zibll .article-nav).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
function aksrt_single_render_prevnext(array $ctx = []): void {
|
||||
$settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : [];
|
||||
// Accept both canonical `prevnext` (Settings DTO) and legacy `prevnext_s`.
|
||||
$enabled = array_key_exists('prevnext', $settings)
|
||||
? !empty($settings['prevnext'])
|
||||
: (!array_key_exists('prevnext_s', $settings) || !empty($settings['prevnext_s']));
|
||||
@@ -522,30 +521,40 @@ if (!function_exists('aksrt_single_render_prevnext')) :
|
||||
return;
|
||||
}
|
||||
|
||||
$prev = get_previous_post();
|
||||
$next = get_next_post();
|
||||
// Zibll: constrain to current category when available.
|
||||
$in_same_term = !empty(get_the_category());
|
||||
$prev = get_previous_post($in_same_term, '', 'category');
|
||||
$next = get_next_post($in_same_term, '', 'category');
|
||||
if (!$prev && !$next) {
|
||||
// Fallback: any post.
|
||||
$prev = get_previous_post();
|
||||
$next = get_next_post();
|
||||
}
|
||||
if (!$prev && !$next) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prev_title = $prev ? get_the_title($prev) : __('无更多文章', 'aksrt');
|
||||
$next_title = $next ? get_the_title($next) : __('无更多文章', 'aksrt');
|
||||
$prev_href = $prev ? get_permalink($prev) : 'javascript:;';
|
||||
$next_href = $next ? get_permalink($next) : 'javascript:;';
|
||||
?>
|
||||
<nav class="post-nav-box theme-box box-body radius8 main-shadow">
|
||||
<?php if ($prev) : ?>
|
||||
<a class="post-nav-box__item post-nav-box__item--prev" href="<?php echo esc_url(get_permalink($prev)); ?>">
|
||||
<span class="post-nav-box__label"><?php esc_html_e('上一篇', 'aksrt'); ?></span>
|
||||
<span class="post-nav-box__title"><?php echo esc_html(get_the_title($prev)); ?></span>
|
||||
</a>
|
||||
<?php else : ?>
|
||||
<span class="post-nav-box__item post-nav-box__item--prev is-empty" aria-hidden="true"></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($next) : ?>
|
||||
<a class="post-nav-box__item post-nav-box__item--next" href="<?php echo esc_url(get_permalink($next)); ?>">
|
||||
<span class="post-nav-box__label"><?php esc_html_e('下一篇', 'aksrt'); ?></span>
|
||||
<span class="post-nav-box__title"><?php echo esc_html(get_the_title($next)); ?></span>
|
||||
</a>
|
||||
<?php else : ?>
|
||||
<span class="post-nav-box__item post-nav-box__item--next is-empty" aria-hidden="true"></span>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
<div class="theme-box" style="height:99px">
|
||||
<nav class="article-nav">
|
||||
<div class="main-bg box-body radius8 main-shadow">
|
||||
<a href="<?php echo $prev ? esc_url($prev_href) : 'javascript:;'; ?>">
|
||||
<p class="muted-2-color"><i class="fa fa-angle-left em12" aria-hidden="true"></i><i class="fa fa-angle-left em12 mr6" aria-hidden="true"></i><?php esc_html_e('上一篇', 'aksrt'); ?></p>
|
||||
<div class="text-ellipsis-2"><?php echo esc_html($prev_title); ?></div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="main-bg box-body radius8 main-shadow">
|
||||
<a href="<?php echo $next ? esc_url($next_href) : 'javascript:;'; ?>">
|
||||
<p class="muted-2-color"><?php esc_html_e('下一篇', 'aksrt'); ?><i class="fa fa-angle-right em12 ml6" aria-hidden="true"></i><i class="fa fa-angle-right em12" aria-hidden="true"></i></p>
|
||||
<div class="text-ellipsis-2"><?php echo esc_html($next_title); ?></div>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
@@ -777,7 +786,7 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_article')) :
|
||||
/**
|
||||
* Main article box.
|
||||
* Main article box (Zibll zib_single_content order).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
@@ -785,49 +794,51 @@ if (!function_exists('aksrt_single_render_article')) :
|
||||
$settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : [];
|
||||
$maxheight = (int) $ctx['content_maxheight'];
|
||||
?>
|
||||
<article <?php post_class('article article-shell main-bg theme-box box-body radius8 main-shadow'); ?>>
|
||||
<article <?php post_class('article main-bg theme-box box-body radius8 main-shadow'); ?>>
|
||||
<?php aksrt_single_render_box_header($ctx); ?>
|
||||
|
||||
<?php if (!empty($settings['yiyan_header'])) : ?>
|
||||
<div class="article-yiyan yiyan-box aksrt-yiyan yiyan--header" data-aksrt-yiyan data-type="hitokoto"></div>
|
||||
<?php endif; ?>
|
||||
<div class="article-content">
|
||||
<?php if (!empty($settings['yiyan_header'])) : ?>
|
||||
<div class="article-yiyan yiyan-box aksrt-yiyan yiyan--header theme-box text-center radius8 main-shadow" data-aksrt-yiyan data-type="hitokoto"></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php do_action('aksrt_single_content_before', get_post()); ?>
|
||||
<?php do_action('aksrt_single_content_before', get_post()); ?>
|
||||
|
||||
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'top')) : ?>
|
||||
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'top')) : ?>
|
||||
<?php aksrt_single_render_pay_box($ctx); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($ctx['front_content'] !== '') : ?>
|
||||
<div class="post_front_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['front_content']); ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($ctx['front_content'] !== '') : ?>
|
||||
<div class="post_front_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['front_content']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="theme-box wp-posts-content entry-content<?php echo $maxheight > 0 ? ' limit-height' : ''; ?>"
|
||||
<?php echo $maxheight > 0 ? ' style="max-height:' . esc_attr((string) $maxheight) . 'px;"' : ''; ?>
|
||||
data-nav="posts"
|
||||
data-maxheight="<?php echo esc_attr((string) $maxheight); ?>"
|
||||
data-aksrt-toc="<?php echo !empty($ctx['show_toc']) ? '1' : '0'; ?>"
|
||||
data-aksrt-toc-depth="<?php echo esc_attr((string) ((int) ($settings['toc_depth'] ?? 3))); ?>"
|
||||
<?php echo !empty($settings['lightbox']) ? ' data-aksrt-lightbox="1"' : ''; ?>>
|
||||
<?php the_content(); ?>
|
||||
<?php
|
||||
wp_link_pages([
|
||||
'before' => '<p class="text-center post-nav-links radius8 padding-6">',
|
||||
'after' => '</p>',
|
||||
]);
|
||||
?>
|
||||
<div class="theme-box wp-posts-content<?php echo $maxheight > 0 ? ' limit-height' : ''; ?>"
|
||||
<?php echo $maxheight > 0 ? ' style="max-height:' . esc_attr((string) $maxheight) . 'px;"' : ''; ?>
|
||||
data-nav="posts"
|
||||
data-maxheight="<?php echo esc_attr((string) ($maxheight > 0 ? max(0, $maxheight - 80) : 0)); ?>"
|
||||
data-aksrt-toc="<?php echo !empty($ctx['show_toc']) ? '1' : '0'; ?>"
|
||||
data-aksrt-toc-depth="<?php echo esc_attr((string) ((int) ($settings['toc_depth'] ?? 3))); ?>"
|
||||
<?php echo !empty($settings['lightbox']) ? ' data-aksrt-lightbox="1"' : ''; ?>>
|
||||
<?php the_content(); ?>
|
||||
<?php
|
||||
wp_link_pages([
|
||||
'before' => '<p class="text-center post-nav-links radius8 padding-6">',
|
||||
'after' => '</p>',
|
||||
]);
|
||||
?>
|
||||
<?php if ($ctx['after_content'] !== '') : ?>
|
||||
<?php echo wp_kses_post((string) $ctx['after_content']); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'bottom')) : ?>
|
||||
<?php aksrt_single_render_pay_box($ctx); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php aksrt_single_render_content_footer($ctx); ?>
|
||||
</div>
|
||||
|
||||
<?php if ($ctx['after_content'] !== '') : ?>
|
||||
<div class="post_after_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['after_content']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'bottom')) : ?>
|
||||
<?php aksrt_single_render_pay_box($ctx); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php aksrt_single_render_actions($ctx); ?>
|
||||
<?php aksrt_single_render_content_footer($ctx); ?>
|
||||
</article>
|
||||
<?php
|
||||
}
|
||||
@@ -914,7 +925,7 @@ if (!function_exists('aksrt_single')) :
|
||||
echo $ctx['breadcrumbs_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} elseif (function_exists('aksrt_breadcrumbs')) {
|
||||
$settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : [];
|
||||
aksrt_breadcrumbs($settings['breadcrumbs_home'] ?? '');
|
||||
aksrt_breadcrumbs($settings['breadcrumbs_home'] ?? ($settings['breadcrumbs_home_text'] ?? ''));
|
||||
}
|
||||
} else {
|
||||
aksrt_single_render_cover($ctx);
|
||||
|
||||
Reference in new issue
Block a user