DedeCMS让channelartlist支持currentstyle属性

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

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

打开include\taglib\channelartlist.lib.php

找到:

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

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

1
2
3
//让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'

1
2
3
4
5
6
7
8
9
10
11
12
{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 @   asqq8  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示