Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📰 Feat: 支持分类导航 & 部分导航逻辑重构 #24

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="navbar-dropdown">
<button class="navbar-button navbar-dropup" id="nav-rise"><span>+</span></button>
<h2>页面</h2>
<ul class="widget-list"><?php Matcha::pageNav($this, "li"); ?></ul>
<ul class="widget-list"><li><a href="<?php $this->options->siteUrl(); ?>" rel="section">首页</a></li><?php Matcha::pageNav($this, "li"); ?></ul>
<h2>分类</h2>
<ul class="widget-list widget-category">
<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
Expand Down
6 changes: 5 additions & 1 deletion includes/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<aside id="sidebar" class="sidebar" role="complementary">
<section class="widget widget-nav sidebar-nav">
<header id="header" class="header"><?php Matcha::siteName(); ?></header>
<ul class="widget-list"><?php Matcha::pageNav($this, "li"); ?></ul>
<ul class="widget-list">
<li><a href="<?php $this->options->siteUrl(); ?>" rel="section">首页</a></li>
<?php Matcha::categoryNav($this, "li"); ?>
<?php Matcha::pageNav($this, "li"); ?>
</ul>
</section>
<!-- 版权信息 -->
<section class="widget sidebar-foot">
Expand Down
25 changes: 21 additions & 4 deletions libs/Matcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ public static function pageNav(Widget_Archive $archive, $tag)

if(Helper::options()->customNav=='' || $data['type']=='addition'){
$archive->widget('Widget_Contents_Page_List')->to($pages);
//首页链接
echo '<'.$tag.'><a href="';
Utils::indexHome();
echo '">首页</a></'.$tag.'>';
//页面列表
while($pages->next()) {
echo '<'.$tag.'><a href="';
Expand All @@ -287,6 +283,27 @@ public static function pageNav(Widget_Archive $archive, $tag)
}
}

/**
* 统一输出分类导航
* html 结构
*/
public static function categoryNav(Widget_Archive $archive, $tag)
{
// 如果开启了分类导航,则输出分类
if(Helper::options()->categoryNav=='able') {
$archive->widget('Widget_Metas_Category_List')->to($categories);
while($categories->next()) {
echo '<'.$tag.'><a href="';
$categories->permalink();
echo '" title="';
$categories->name();
echo '">';
$categories->name();
echo '</a></'.$tag.'>';
}
}
}

/**
* 统一输出站点标题及副标题
* html 结构
Expand Down
12 changes: 12 additions & 0 deletions libs/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ function themeConfig($form) {
$relatedLinks = new Typecho_Widget_Helper_Form_Element_Textarea('relatedLinks', NULL, NULL, _t('首页「相关链接」内容'), _t('
<p class="description">使用特定的 JSON 格式书写,可以在首页文章目录之前展示一个相关链接版块,详情请查看说明文档</p>'));
$form->addInput($relatedLinks);
// 分类导航
$categoryNav = new Typecho_Widget_Helper_Form_Element_Radio('categoryNav', array(
'able' => _t('启用'),
'disable' => _t('停用'),
),
'disable',
_t('是否启用侧边栏分类导航'),
_t('
启用后,将在侧边栏首页和独立页面中间加入所有分类页面。
')
);
$form->addInput($categoryNav->addRule('required', _t('此处必须设置')));

/**
* 附加功能
Expand Down