织梦一二级导航菜单被点击顶级栏目高亮(加class)解决方法

织梦一二级导航菜单被点击的栏目高亮显示方法详解,废话不多说直接举例说明:

织梦一级菜单被点击栏目高亮调用方法:

{dede:channel typeid ='1'  type ='son' currentstyle="<li class='on'><a href='~typelink~'>~typename~</a></li>"}

<li><a href='[field:typeurl/]'>[field:typename/]</a></li>

{/dede:channel}
*注:对当前栏目列表设置了class='on',可以通过css样式为其设置背景图片或颜色,从而达到栏目高亮的效果。
首页判断是否添加class 调用方法:
 <li><a {dede:field name=typeid runphp="yes"}(@me=="")? @me=" class='on'":@me="";{/dede:field} href="{dede:global.cfg_basehost/}">网站首页</a></li>
*注:首页判断是否添加class='on'属性
织梦二级菜单被点击栏目高亮调用方法:
       第一步:因为织梦默认dede:channelartlist标签是不支持currentstyle属性的,所以接加下先修改channelartlist.lib.php
               1:打开include\taglib\channelartlist.lib.php,找到$pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]);
               2:替换成如图所示:

                      $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 : 'navOn';  

                          }  

                        else{  

                        $pv->Fields['currentstyle'] = '';  

                         }  


 

    第二步:前台调用:
     {dede:channelartlist typeid='top' currentstyle='on' } 

           <li><a  class="{dede:field.currentstyle/}" href="{dede:field name='none'/}" >{dede:field name='typename'/}</a>

              <ul>{dede:channel type='son' noself='yes'}    

                 <li><a href="[field:typelink/]" >[field:typename/]</a></li>

               {/dede:channel}

              </ul>

           </li>

      {/dede:channelartlist} 
*注:生成栏目,循环出的顶级栏目li会有一个class=“on”的属性。页面效果如图所示:

转载于:https://www.cmswu.com/eckf/406.html 

猜你喜欢

转载自blog.csdn.net/weixin_42694072/article/details/81945251