导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Docs Mode: Sidebar Navigation
|
||||
*
|
||||
* 文档模式侧边栏:显示文档目录树,当前章节高亮。
|
||||
* Uses AKSRT_Docs_Presenter for tree construction.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$current_id = get_the_ID();
|
||||
$parent_id = wp_get_post_parent_id($current_id);
|
||||
$root_id = $parent_id ?: $current_id;
|
||||
|
||||
$presenter = class_exists('AKSRT_Docs_Presenter') ? AKSRT_Docs_Presenter::get_instance() : null;
|
||||
|
||||
if ($presenter) {
|
||||
$doc_pages = $presenter->get_flat_tree($root_id, 3);
|
||||
} else {
|
||||
$doc_pages = get_pages([
|
||||
'child_of' => $root_id,
|
||||
'sort_column' => 'menu_order, post_title',
|
||||
'sort_order' => 'ASC',
|
||||
'parent' => $root_id,
|
||||
]);
|
||||
}
|
||||
|
||||
$root_page = get_post($root_id);
|
||||
|
||||
// Quick search for docs
|
||||
$doc_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_docs_mode_settings() : [];
|
||||
$show_search = !empty($doc_settings['toc_enabled']);
|
||||
?>
|
||||
<aside class="aksrt-doc-sidebar" role="navigation" aria-label="<?php esc_attr_e('文档导航', 'aksrt'); ?>">
|
||||
<div class="aksrt-doc-sidebar__header">
|
||||
<a href="<?php echo esc_url(get_permalink($root_id)); ?>" class="aksrt-doc-sidebar__root">
|
||||
<i class="fas fa-book aksrt-doc-sidebar__root-icon"></i>
|
||||
<span><?php echo esc_html($root_page->post_title ?? __('文档', 'aksrt')); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php if ($show_search) : ?>
|
||||
<div class="aksrt-doc-sidebar__search">
|
||||
<input type="text" class="aksrt-doc-sidebar__search-input" placeholder="<?php esc_attr_e('搜索文档...', 'aksrt'); ?>" aria-label="<?php esc_attr_e('搜索文档', 'aksrt'); ?>">
|
||||
<i class="fas fa-search aksrt-doc-sidebar__search-icon"></i>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($doc_pages)) : ?>
|
||||
<ul class="aksrt-doc-sidebar__nav">
|
||||
<?php foreach ($doc_pages as $dp) :
|
||||
$depth = isset($dp->_depth) ? (int) $dp->_depth : 0;
|
||||
$is_current = ((int) $dp->ID === $current_id);
|
||||
$is_ancestor = ((int) $dp->ID === $parent_id);
|
||||
$li_class = 'aksrt-doc-sidebar__item';
|
||||
if ($is_current) $li_class .= ' is-current';
|
||||
if ($is_ancestor) $li_class .= ' is-ancestor';
|
||||
if ($depth > 0) $li_class .= ' aksrt-doc-sidebar__item--depth-' . $depth;
|
||||
|
||||
$has_children = false;
|
||||
if ($presenter) {
|
||||
$sub = get_pages(['parent' => $dp->ID, 'post_status' => 'publish', 'fields' => 'ids']);
|
||||
$has_children = !empty($sub);
|
||||
} else {
|
||||
$sub_pages = get_pages(['child_of' => $dp->ID, 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'parent' => $dp->ID]);
|
||||
$has_children = !empty($sub_pages);
|
||||
}
|
||||
$is_open = $is_current || $is_ancestor;
|
||||
?>
|
||||
<li class="<?php echo esc_attr($li_class); ?>" style="<?php echo $depth > 0 ? 'padding-left:' . ($depth * 16) . 'px;' : ''; ?>">
|
||||
<a href="<?php echo esc_url(get_permalink($dp->ID)); ?>" class="aksrt-doc-sidebar__link<?php echo $is_current ? ' is-active' : ''; ?>">
|
||||
<?php if ($has_children) : ?>
|
||||
<i class="fas fa-chevron-<?php echo $is_open ? 'down' : 'right'; ?> aksrt-doc-sidebar__toggle" aria-hidden="true"></i>
|
||||
<?php endif; ?>
|
||||
<span><?php echo esc_html($dp->post_title); ?></span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</aside>
|
||||
Reference in new issue
Block a user