MENU

typecho的简单调用

April 2, 2023 • 建站教程阅读设置

typecho默认是不在菜单中显示栏目链接的,只显示页面的名称和链接,这一点对于我们可能不太适应,但我们可以header.php文件中,找到应对的位置,并增加如下代码,就可以显示栏目分类链接到菜单中了:

<?php $this->widget('Widget_Metas_Category_List')->to($category);?>
<?php while($category->next()):?>
<li class="nav-item <?php if($this->is('category', $category->slug)): ?>active<?php endif;?>">
<a class="nav-link" href="<?php $category->permalink();?>" title="<?php $category->name();?>"><?php $category->name();?></a>
</li>
<?php endwhile;?>

但是增加地栏目分类到菜单,你点开栏目下的文章,发现在阅读文章时,文章所属的栏目并没有高亮,此时使用下面的代码可实现栏目链接高亮:

<?php $this->widget('Widget_Metas_Category_List')->to($category);?>
<?php while ($category->next()):?>
<a <?php if($this->is('post')):?>
<?php if($this->category == $category->slug):?>class="current"<?php endif;?>
<?php else:?>
<?php if($this->is('category', $category->slug)):?>class="current"<?php endif;?>
<?php endif;?> href="<?php $category->permalink();?>"><?php $category->name();?>
</a>
<?php endwhile; ?>