今天看了看phpcms 写到二级导航时发现点问题,查询导航栏的信息时返回的$r[arrchildid]与自己想象的不符,文档上说是返回子栏目id但是却有些不同。
开始的思路:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<ul class = "nav navbar-nav" > <li class = "active" ><a href= "{siteurl($siteid)}" >首页</a></li> {pc:content action= "category" catid= "0" num= "10" siteid= "$siteid" order= "listorder ASC" } {loop $data $r } { if $r [arrchildid]} <li class = "dropdown" > <a href= "{$r[url]}" class = "dropdown-toggle" child= "{$r[arrchildid]}" data-toggle= "dropdown" >{ $r [catname]}<b class = "caret" ></b></a> <ul class = "dropdown-menu" > {pc:content action= "category" catid= "$r[catid]" num= "10" siteid= "$siteid" order= "listorder ASC" return = "data2" } {loop $data2 $v } <li><a href= "{$v[url]}" >{ $v [catname]}</a></li> {/loop} {/pc} </ul> </li> {/ if } {/loop} {/pc} </ul> |
大致思路:查询该文档下是否有子栏目id,如果有则输出二级导航。代码中第5行是检测该栏目下是否有子栏目id,但是我发现当没有子栏目时会返回当前栏目的id导致判断无法达到预期的效果,所以改变思路,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<ul class = "nav navbar-nav" > <li class = "active" ><a href= "{siteurl($siteid)}" >首页</a></li> {pc:content action= "category" catid= "0" num= "10" siteid= "$siteid" order= "listorder ASC" } {loop $data $r } { if $r [arrchildid] != $r [catid]} <li class = "dropdown" > <a href= "{$r[url]}" class = "dropdown-toggle" child= "{$r[arrchildid]}" data-toggle= "dropdown" >{ $r [catname]}<b class = "caret" ></b></a> <ul class = "dropdown-menu" > {pc:content action= "category" catid= "$r[catid]" num= "10" siteid= "$siteid" order= "listorder ASC" return = "data2" } {loop $data2 $v } <li><a href= "{$v[url]}" >{ $v [catname]}</a></li> {/loop} {/pc} </ul> </li> { else } <li><a href= "{$r[url]}" >{ $r [catname]}</a></li> {/ if } {/loop} {/pc} </ul> |
判断获取到的子栏目id是否等于该栏目id,等于则表示没有子栏目,不等于则表示有子栏目且显示子栏目
以上所述是小编给大家介绍的PHPCMS V9 添加二级导航的思路详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!