DedeCMS让channelartlist支持currentstyle属性

织梦一二级导航菜单被点击顶级栏目高亮(加class)解决方法,DedeCMS让channelartlist支持currentstyle属性。

dedecms默认模板的channelartlist是不支持currentstyle属性的。currentstyle属性在导航中应用的比较多,可以实现循环调用栏目后,当前页<li>标签获得一个class="自定义命名"的属性,具体作用就不做说明了,需要修改文件。

打开include\taglib\channelartlist.lib.php

找到:

$pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]);

  在以上代码的下方添加如下代码:

//让channelarclist支持currentstyle属性 
if($typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['id'] || $typeids[$i]['id'] == $refObj->TypeLink->TypeInfos['topid'] ){ $pv->Fields['currentstyle'] = $currentstyle ? $currentstyle : 'nLi on'; } else{ $pv->Fields['currentstyle'] = 'nLi'; } 
//让channelarclist支持currentstyle属性end

调用代码如下:(给导航调用代码添加: currentstyle='current'

      {dede:channelartlist typeid='1,2,3,4,5,6,7' currentstyle='current'}
		<div class="nav-item-box maskLayer-relative">
			<div class="hover-box">
			    <a class="nav-item {dede:field.currentstyle/}" href="{dede:field name='typeurl'/}" title="{dede:field name='typename'/}">{dede:field name='typename'/}</a>
				<div class="nav-dropdown">
				    {dede:channel type='son' noself='yes' }
				    <a class="nav-dropdown-item only-oneline" href="[field:typelink/]" title="[field:typename/]">[field:typename/]</a>
				    {/dede:channel} 
				</div>
			</div>
		</div>
      {/dede:channelartlist}

  

效果如图:(会在样式里添加一个current,然后再在CSS给current添加样式)

 

posted @ 2024-04-18 19:58  asqq8  阅读(39)  评论(0编辑  收藏  举报