Add category menu navigation and article category menu highlighting to typecho

By default, typecho does not display column links in the menu, but only displays the name and link of the page. This may not be suitable for us, but we can find the corresponding position in the header.php file and add the following code to display it The column category is linked to the menu:

<?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;?>

But adding the column category to the menu, you click on the article under the column, and find that when reading the article, the column to which the article belongs is not highlighted. At this time, the following code can be used to highlight the link of the column:

<?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; ?>

This article was created by Program Say and is licensed under the CC BY 4.0 license.

Guess you like

Origin blog.csdn.net/diqiudq/article/details/126613205