首页 > CMS教程 > 其他CMS    日期:2019-12-19 / 来自互联网 / 浏览

主要实现分类页面、文章页面,自动识别当前分类并添加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'];
    }
}

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章

1 2 3 4 5