Typecho分类导航代码
主要实现分类页面、文章页面,自动识别当前分类并添加CSS样式。首页会被识别为默认分类。
导航代码:
<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while($categories->next()): ?>
<?php if ($categories->levels === 0): ?>
<a<?php if($this->is('category', $categories->slug)||($categories->slug == topcategory($this->category))): ?> class="current"<?php endif; ?> href="<?php $categories->permalink(); ?>"><?php $categories->name(); ?></a>
<?php endif; ?>
<?php endwhile; ?>
获取文章所属分类的父分类函数:
function topcategory($slug) {
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$rs = $db->fetchRow($db->select()->from($prefix.'metas')->where('slug = ?', $slug)->limit(1));
if($rs['parent']==0){
return $rs['slug'];
}
else {
$rs2 = $db->fetchRow($db->select()->from($prefix.'metas')->where('mid = ?', $rs['parent'])->limit(1));
return $rs2['slug'];
}
}
您可能感兴趣的文章
声明:本文来自互联网或用户投稿,该文观点仅代表作者本人,不代表本站立场。文章及其配图仅供学习和交流之用,版权归原作者所有,如有内容侵权或者其他违规问题,请联系本站处理。


