onethink二级导航调用
<ul class="nav-main">
//添加tree参数 <think:nav name="nav" tree="true"> <li class="dropdown-hover"><a href="{$nav.url|get_nav_url}">{$nav.title}</a>
//判断$nav['_']是否为空,不为空则表示有二级导航 <if condition="is_array($nav['_'])"> <ul class="dropdown-menu-nav-main"> <volist name="nav['_']" id="vo"> <li><a href="{$vo.url|get_nav_url}">{$vo.title}</a></li> </volist> </ul> </if> </li> </think:nav> </ul>
可以在Thinkphp/Libray/OT/TagLib/Think.class.php 文件内搜索_nav方法,打印输出,查看数组
/* 导航列表 */ public function _nav($tag, $content){ $field = empty($tag['field']) ? 'true' : $tag['field']; $tree = empty($tag['tree'])? false : true; $parse = $parse = '<?php '; $parse .= '$__NAV__ = M(\'Channel\')->field('.$field.')->where("status=1")->order("sort")->select();'; if($tree){ $parse .= '$__NAV__ = list_to_tree($__NAV__, "id", "pid", "_");'; }
//个人添加的dump($__NAV__); 打印输出数组,发现二级导航有键为_ ["_"] 的数组,所以调用导航时,判断键为_的元素是否为空,即可
$parse .= 'dump($__NAV__);?><volist name="__NAV__" id="'. $tag['name'] .'">'; $parse .= $content; $parse .= '</volist>'; return $parse; }