网站目录_分类目录_网站收录_速建时代目录

站长资讯

网站建设CMS-头部导航配置

php后端代码

调用

 //前端导航和底部导航缓存  cache缓存配置
        if (!cache('cateRes')){
            cache('cateRes', $this->getCate(false), 3600);
            $cateRes=cache('cateRes');
        }else{
            $cateRes=cache('cateRes');
        }

php查询返回

//前端导航和底部导航
    public function getCate($bottom=false){

        if($bottom){//底部导航
            $cateRes=Db::name('cate')->order('sort DESC')->where(array('pid'=>0,'status'=>1,'bottom_nav'=>1,'uid'=>$this->uid))->order('sort desc')->select()->all();
        }else{//顶部导航
            $cateRes=Db::name('cate')->order('sort DESC')->where(array('pid'=>0,'status'=>1,'uid'=>$this->uid))->order('sort desc')->select()->all();
        }
        foreach ($cateRes as $k => $v) {
            $cateRes[$k]['children']=Db::name('cate')->where(array('pid'=>$v['id'],'status'=>1,'uid'=>$this->uid))->order('sort desc')->select()->all();
        }
        return $cateRes;
    }

前端调用

 {volist name="cateRes" id="cate"}
          
              {$cate.cate_name}
            {if condition="count($cate['children']) neq 0" }
            
              {volist name="$cate['children']" id="sonCate"}
              {$sonCate.cate_name}
              {/volist}
            
            {/if}
          
{/volist}
{if condition="$cate['id'] eq $topCates.id" }active{/if}//判断当前栏目id所在

{$cate.cate_attr|makeurl=###,$cate.id}//链接带有跳转或直接访问等属性

{if condition="count($cate['children']) neq 0" }判断是否有二级栏目

{volist name="$cate['children']" id="sonCate"}//循环二级栏目


标签: