織夢一二級導航選單被點選頂級欄目高亮(加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
呼叫程式碼如下:
{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新增樣式)