dede列表页调用二三级导航栏(转载)

dede列表页调用二三级导航栏
1.首先看一下调用的代码如下:

<ul>
{dede:channelartlist typeid='3'}
<liclass="li_biaoti"><a class="s"href="{dede:field name='typeurl'/}" >{dede:fieldname='typename'/}</a></li>
{dede:channel type='son'noself='yes'}
<li><a class="t"href="[field:typelink/]">[field:typename/]</a></li>
{/dede:channel}
{/dede:channelartlist}
</ul>
这段代码的意思是查询栏目id为3的子栏目然后在查询子栏目的子栏目。效果如图所示:

 

这样会出现一个问题,就是如果该栏目没有子栏目的话,就会取他的同级栏目,那么如何解决{dede:channeltype='son'}无子栏目时取同级栏目问题呢?

其实很简单:

打开:include\taglib\channel.lib.php文件。
找到
if($type=='son' && $reid!=0&& $totalRow==0)
改成
if($type=='son' && $reid!=0&& $totalRow==0&& $noself=='')
这样就对了。


dede让channelartlist标签支持currentstyle属性
打开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 : 'current';
}
else{
$pv->Fields['currentstyle'] = '';
}

网上找到的一般没有加$typeids[$i]['id'] ==$refObj->TypeLink->TypeInfos['topid']
添加这个后才能对二级栏目也起作用
调用方法:
{dede:channelartlist typeid='2' currentstyle='current'}
<li class='{dede:field.currentstyle/}'><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li>
。。。
{/dede:channelartlist}

如果是当前栏目则 li的class属性显示current,否则显示class='' ,也可以修改currentstyle='这里改为你需要的类名'。
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/wzl505/article/details/79104427

posted @ 2024-07-22 17:39  雪莉06  阅读(3)  评论(0编辑  收藏  举报