feat(widgets): wire PostsNavs TOC shell to page-template scrollspy
Match built-in single sidebar .posts-nav-box.toc-widget/.toc-list so the sidebar widget is filled (≥3 headings), supports multiple TOC shells, and removes empty chrome.
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
/**
|
||||
* In-article / topic TOC shell (zibll widget_ui_posts_navs parity).
|
||||
*
|
||||
* Frontend JS fills `.posts-nav-box` from heading outline when present.
|
||||
* Shell matches the built-in single sidebar TOC so page-template.js can fill
|
||||
* `.posts-nav-box.toc-widget > .toc-list` from `[data-nav]` headings.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -18,8 +19,8 @@ class WidgetPostsNavs extends \WP_Widget {
|
||||
'aksrt_posts_navs',
|
||||
esc_html__('AKSRT 文章目录树', 'aksrt'),
|
||||
[
|
||||
'description' => esc_html__('显示当前文章/帖子标题目录,非详情页不输出。标题超过 3 个才显示。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_posts_navs',
|
||||
'description' => esc_html__('显示当前文章/帖子标题目录,非详情页不输出。标题超过 2 个才填充。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_posts_navs',
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -35,16 +36,28 @@ class WidgetPostsNavs extends \WP_Widget {
|
||||
|
||||
$data_title = $title;
|
||||
if ($mini_title !== '') {
|
||||
$data_title .= ' · ' . $mini_title;
|
||||
$data_title .= ($data_title !== '' ? ' · ' : '') . $mini_title;
|
||||
}
|
||||
if ($data_title === '') {
|
||||
$data_title = __('文章目录', 'aksrt');
|
||||
}
|
||||
|
||||
// Mirror aksrt-single-render built-in TOC shell so page-template.js binds.
|
||||
$classes = 'zib-widget toc-widget posts-nav-box';
|
||||
if ($in_affix) {
|
||||
$classes .= ' is-affix';
|
||||
}
|
||||
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="widget-container">';
|
||||
printf(
|
||||
'<div class="posts-nav-box"%s%s></div>',
|
||||
'<div class="%s"%s data-title="%s" aria-label="%s">',
|
||||
esc_attr($classes),
|
||||
$in_affix ? ' data-affix="true"' : '',
|
||||
$data_title !== '' ? ' data-title="' . esc_attr($data_title) . '"' : ''
|
||||
esc_attr($data_title),
|
||||
esc_attr($data_title)
|
||||
);
|
||||
echo '<h3 class="widget-title toc-widget__title">' . esc_html($data_title) . '</h3>';
|
||||
echo '<ol class="toc-list"></ol>';
|
||||
echo '</div>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
@@ -68,7 +81,7 @@ class WidgetPostsNavs extends \WP_Widget {
|
||||
<?php esc_html_e('侧栏随动(仅侧边栏)', 'aksrt'); ?>
|
||||
</label>
|
||||
</p>
|
||||
<p class="description"><?php esc_html_e('请添加到文章/帖子侧栏。正文 H2–H4 超过 3 个时前端才会填充目录。', 'aksrt'); ?></p>
|
||||
<p class="description"><?php esc_html_e('请添加到文章/帖子侧栏。正文标题 ≥3 个时由前端填充目录;无标题则自动移除。', 'aksrt'); ?></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user