dede:channelartlist嵌套读取二级栏目并设置当前栏目高亮

2015年-03月-20日

百度一下,网上有不少的方法,鱼龙混杂大多不可用,道成最近正字做一个案例用到这个嵌套,顺便给大家分享一套完整的方案
首先:修改PHP文件
打开:include\taglib\channelartlist.lib.php
搜索:$pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]); 注意不要含有空格,否则搜索不到
然后在下方添加代码:

if($typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['id'] || $typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['topid'] ){ 
            $pv->Fields['currentstyle'] = $currentstyle ? $currentstyle : 'active'; 
        } 
        else{ 
            $pv->Fields['currentstyle'] = ''; 
        } 
其中active为您需要用到的当前样式的css
--------------
本案例用到的类为active

.topnav li a.active{background:url(../images/nav_bg.png) no-repeat center 0px; color:#fff;}

然后在调用的时候
 <ul class="topnav">   
{dede:channelartlist row=6 typeid='top'}  
<li><a class='{dede:field.currentstyle/}' href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a>
<ul  style="display: none;">  
{dede:channel type='son' noself='true'}  
<li><a href='[field:typelink/]'>[field:typename/]</a><span>|</span></li>  
{/dede:channel}  
</ul>  
</li>  
{/dede:channelartlist} 
</ul>

网上有朋友说不要加class=‘’ 其实是要加的,在这里系统把'{dede:field.currentstyle/}' 转换成了 active
我这里的调用代码是嵌套了二级栏目