TP5 首页导航一级和二级分类

<ul id="jsddm">
<li><a class="navi_home" href="{:url('/index/index')}">首页</a></li>
{volist name="cateres" id="cate"}
<li> 栏目类型: 1:列表栏目 artlist ,2:单页栏目 page,3:图片列表 imglist
{if condition="$cate.type eq 1"}
<a href="http://127.0.0.1/bike/public/index.php/index/artlist/index/cateid/{$cate.id}">{$cate.catename}</a>
{elseif condition="$cate.type eq 2"}
<a href="http://127.0.0.1/bike/public/index.php/index/page/index/cateid/{$cate.id}">{$cate.catename}</a>
{elseif condition="$cate.type eq 3"}
<a href="http://127.0.0.1/bike/public/index.php/index/imglist/index/cateid/{$cate.id}">{$cate.catename}</a>
{/if}
{if condition="$cate.children neq 0"} 如果子栏目不为0
<ul>
<?php foreach($cate['children'] as $k2=>$v2): ?>
<li>
{if condition="$v2.type eq 1"}
<a href="http://127.0.0.1/bike/public/index.php/index/artlist/index/cateid/{$v2.id}">{$v2.catename}</a>
{elseif condition="$v2.type eq 2"}
<a href="http://127.0.0.1/bike/public/index.php/index/page/index/cateid/{$v2.id}">{$v2.catename}</a>
{elseif condition="$v2.type eq 3"}
<a href="http://127.0.0.1/bike/public/index.php/index/imglist/index/cateid/{$v2.id}">{$v2.catename}</a>
{/if}
</li>
<?php endforeach; ?>
</ul>
{/if}
</li>
{/volist}
</ul>

     public function  getNavCates(){
         //获取导航列表及子列表
         $cateres=db('cate')->where('pid',0)->select();
         foreach ($cateres as $k=> $v){
             $children=db('cate')->where('pid',$v['id'])->select();
             if($children){
                 $cateres[$k]['children']=$children;
                // dump($children);die;
             }else{
                 $cateres[$k]['children']=0;
             }
         }
       //  dump($cateres);die;
         $this->assign('cateres',$cateres);
     }

 

posted @ 2017-10-19 15:53    阅读(3884)  评论(0编辑  收藏  举报