feat: deepen single post experience
This commit is contained in:
1 parent
a00db4538f
commit
2086f938ed
8 files changed
+265
-81
No files matched your search
@@ -29,6 +29,7 @@ require_once AKSRT_DIR . '/inc/helpers/aksrt-single-components.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-single.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-yiyan.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-single-render.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-single-aside.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive-filters.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-comments.php';
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Single-post sidebar composition.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_single_render_overview_widget')) :
|
||||
/**
|
||||
* Render a useful fallback when no article sidebar widgets are configured.
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
function aksrt_single_render_overview_widget(array $ctx): void {
|
||||
$post_id = (int) ($ctx['post_id'] ?? get_the_ID());
|
||||
$categories = get_the_category($post_id);
|
||||
$primary_category = !empty($categories) && $categories[0] instanceof WP_Term ? $categories[0] : null;
|
||||
$modified = get_the_modified_date('', $post_id);
|
||||
$overview_items = is_array($ctx['meta_items_secondary'] ?? null) ? $ctx['meta_items_secondary'] : [];
|
||||
?>
|
||||
<section class="zib-widget single-overview-widget" aria-labelledby="single-overview-title">
|
||||
<h3 id="single-overview-title" class="single-overview-widget__title">
|
||||
<i class="far fa-file-alt" aria-hidden="true"></i>
|
||||
<?php esc_html_e('文章概览', 'aksrt'); ?>
|
||||
</h3>
|
||||
<dl class="single-overview-widget__list">
|
||||
<?php if ($primary_category instanceof WP_Term) : ?>
|
||||
<div><dt><?php esc_html_e('分类', 'aksrt'); ?></dt><dd><a href="<?php echo esc_url(get_category_link($primary_category)); ?>"><?php echo esc_html($primary_category->name); ?></a></dd></div>
|
||||
<?php endif; ?>
|
||||
<div><dt><?php esc_html_e('浏览', 'aksrt'); ?></dt><dd><?php echo esc_html(number_format_i18n((int) ($ctx['views'] ?? 0))); ?></dd></div>
|
||||
<div><dt><?php esc_html_e('评论', 'aksrt'); ?></dt><dd><a href="<?php echo esc_url(get_comments_link($post_id)); ?>"><?php echo esc_html(number_format_i18n((int) ($ctx['comment_count'] ?? 0))); ?></a></dd></div>
|
||||
<?php foreach ($overview_items as $item) : ?>
|
||||
<?php if (is_array($item) && !empty($item['text'])) : ?>
|
||||
<div><dt><i class="<?php echo esc_attr((string) ($item['icon'] ?? 'far fa-circle')); ?>" aria-hidden="true"></i></dt><dd><?php echo esc_html((string) $item['text']); ?></dd></div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($modified !== '') : ?>
|
||||
<div><dt><?php esc_html_e('更新', 'aksrt'); ?></dt><dd><?php echo esc_html($modified); ?></dd></div>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_aside')) :
|
||||
/**
|
||||
* Render the page-owned single sidebar.
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
function aksrt_single_render_aside(array $ctx): void {
|
||||
if (empty($ctx['show_aside']) || wp_is_mobile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$has_article_widgets = is_active_sidebar('all_sidebar_top')
|
||||
|| is_active_sidebar('sidebar-article')
|
||||
|| is_active_sidebar('all_sidebar_bottom');
|
||||
?>
|
||||
<div class="sidebar" role="complementary" aria-label="<?php esc_attr_e('侧栏', 'aksrt'); ?>">
|
||||
<?php if (!empty($ctx['has_download'])) : ?>
|
||||
<?php get_template_part('templates/parts/resource-meta-box'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$has_article_widgets) : ?>
|
||||
<?php aksrt_single_render_overview_widget($ctx); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($ctx['show_toc'])) : ?>
|
||||
<div class="zib-widget toc-widget posts-nav-box" data-title="<?php echo esc_attr((string) ($ctx['toc_title'] ?? __('文章目录', 'aksrt'))); ?>">
|
||||
<h3><?php echo esc_html((string) ($ctx['toc_title'] ?? __('文章目录', 'aksrt'))); ?></h3>
|
||||
<ol class="toc-list"></ol>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_active_sidebar('all_sidebar_top')) : ?>
|
||||
<?php dynamic_sidebar('all_sidebar_top'); ?>
|
||||
<?php endif; ?>
|
||||
<?php if (is_active_sidebar('sidebar-article')) : ?>
|
||||
<?php dynamic_sidebar('sidebar-article'); ?>
|
||||
<?php endif; ?>
|
||||
<?php if (is_active_sidebar('all_sidebar_bottom')) : ?>
|
||||
<?php dynamic_sidebar('all_sidebar_bottom'); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
@@ -176,6 +176,15 @@ if (!function_exists('aksrt_single_render_box_header')) :
|
||||
'show_time' => empty($settings['hide_time']),
|
||||
'meta_html' => empty($ctx['show_cover']) ? (string) ($ctx['meta_box_html'] ?? '') : '',
|
||||
]);
|
||||
$reading_meta = is_array($ctx['meta_items_secondary'] ?? null) ? $ctx['meta_items_secondary'] : [];
|
||||
if ($reading_meta !== []) :
|
||||
?>
|
||||
<div class="article-reading-meta" aria-label="<?php esc_attr_e('阅读信息', 'aksrt'); ?>">
|
||||
<?php foreach ($reading_meta as $item) : ?>
|
||||
<span><i class="<?php echo esc_attr((string) ($item['icon'] ?? 'far fa-file-alt')); ?>" aria-hidden="true"></i><?php echo esc_html((string) ($item['text'] ?? '')); ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
@@ -389,9 +398,19 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
$q['post__not_in'] = [(int) $cur];
|
||||
}
|
||||
if ($card_orderby === 'views') {
|
||||
$q['meta_key'] = 'views';
|
||||
$q['orderby'] = 'meta_value_num';
|
||||
$q['order'] = 'DESC';
|
||||
$q['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
'views_value' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'EXISTS',
|
||||
'type' => 'NUMERIC',
|
||||
],
|
||||
'views_missing' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
];
|
||||
$q['orderby'] = ['views_value' => 'DESC', 'date' => 'DESC'];
|
||||
} elseif ($card_orderby === 'comment_count') {
|
||||
$q['orderby'] = 'comment_count';
|
||||
$q['order'] = 'DESC';
|
||||
@@ -657,8 +676,19 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
$args['orderby'] = 'modified';
|
||||
break;
|
||||
case 'views':
|
||||
$args['meta_key'] = 'aksrt_post_views';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
'views_value' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'EXISTS',
|
||||
'type' => 'NUMERIC',
|
||||
],
|
||||
'views_missing' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
];
|
||||
$args['orderby'] = ['views_value' => 'DESC', 'date' => 'DESC'];
|
||||
break;
|
||||
case 'relevance':
|
||||
default:
|
||||
@@ -938,42 +968,3 @@ if (!function_exists('aksrt_single_render_after_box')) :
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_aside')) :
|
||||
/**
|
||||
* Page-owned single aside (not a generic sidebar prepend hack).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
function aksrt_single_render_aside(array $ctx): void {
|
||||
if (empty($ctx['show_aside']) || wp_is_mobile()) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="sidebar" role="complementary" aria-label="<?php esc_attr_e('侧栏', 'aksrt'); ?>">
|
||||
<?php if (!empty($ctx['has_download'])) : ?>
|
||||
<?php get_template_part('templates/parts/resource-meta-box'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($ctx['show_toc'])) : ?>
|
||||
<div class="zib-widget toc-widget posts-nav-box" data-title="<?php echo esc_attr((string) $ctx['toc_title']); ?>">
|
||||
<h3><?php echo esc_html((string) $ctx['toc_title']); ?></h3>
|
||||
<ol class="toc-list"></ol>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_active_sidebar('all_sidebar_top')) : ?>
|
||||
<?php dynamic_sidebar('all_sidebar_top'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_active_sidebar('sidebar-article')) : ?>
|
||||
<?php dynamic_sidebar('sidebar-article'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_active_sidebar('all_sidebar_bottom')) : ?>
|
||||
<?php dynamic_sidebar('all_sidebar_bottom'); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
Reference in new issue
Block a user