织梦一二级导航菜单被点击顶级栏目高亮(加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 调用方法:网站首页的位置把class的属性直接在dede判断.如果本身有多个class样式.本来的除了on以外.都不能删.继续保留
 <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”的属性。页面效果如图所示:

发表评论