Discuz! Board

 找回密码
 立即注册

DZ 主导航循环代码及导航高亮优化方法

[复制链接]
7
天涯海角 发表于 2020-7-7 15:42:44

版主 |主题 64|帖子 97|积分 104

默认主导航代码:
<!--{loop $_G['setting']['navs'] $nav}-->
        <!--{if $nav['available'] && (!$nav['level'] || ($nav['level'] == 1 && $_G['uid']) || ($nav['level'] == 2 && $_G['adminid'] > 0) || ($nav['level'] == 3 && $_G['adminid'] == 1))}--><li {if $mnid == $nav[navid]}class="a" {/if}$nav[nav]></li><!--{/if}-->
<!--{/loop}-->

移植到新模板上高亮功能失效
修改判断 {if $mnid == $nav[navid]}class="a" {/if}{if $mnid == $nav[navid] || substr($_SERVER['REQUEST_URI'], 1) == str_replace('./', '', $nav[filename])}class="on" {/if} 完美解决。

完整代码:
<!--{loop $_G['setting']['navs'] $nav}-->
        <!--{if $nav['available'] && (!$nav['level'] || ($nav['level'] == 1 && $_G['uid']) || ($nav['level'] == 2 && $_G['adminid'] > 0) || ($nav['level'] == 3 && $_G['adminid'] == 1))}--><li {if $mnid == $nav[navid] || substr($_SERVER['REQUEST_URI'], 1) == str_replace('./', '', $nav[filename])}class="on" {/if}$nav[nav]></li><!--{/if}-->
<!--{/loop}-->

一地纸 ( 闽ICP备09072999号 )

GMT+8, 2020-9-23 08:04

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表