问题:typecho分类列表,如何对当前分类增加active样式?
解决:使用$categorys->slug
方法:
<ul class="navbar-nav mr-auto">
<li class="nav-item<?php if($this->is('index')):?> current<?php endif;?>">
<a class="nav-link" href="<?php $this->options->siteUrl(); ?>">
<span><?php _e('首页'); ?></span></a>
</li>
<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?>
<?php while($categorys->next()): ?>
<?php if ($categorys->levels === 0): ?>
<li class="nav-item
<?php if($this->is('post')):?>
<?php if($this->category == $categorys->slug):?>
current<?php endif;?>
<?php else:?>
<?php if($this->is('category', $categorys->slug)):?>
current<?php endif;?>
<?php endif;?>">
<a class="nav-link" href="<?php $categorys->permalink(); ?>"
title="<?php $categorys->name(); ?>">
<span><?php $categorys->name(); ?></span></a>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
参考:ttps://www.psay.cn/code/131.html