Home > Article > Backend Development > Code examples on secondary navigation and highlighting in ThinkPhp3.2
Nothing to do, take notes
The implementation of secondary navigation is a secondary linkage, um
Let’s take a look at the database first. I like to use one table. There are many tables. It won’t be fun anymore
The second-level code name is just the code name of the first-level navigation. It’s simple. Chestnut;
Code part:
Look at the controller, the big head is here:
<?php namespace Otcms\controller; use Think\controller; use Otcms\controller\WxhController; use Think\index; class WxhController extends Controller { public function index() { $cha = M('article'); $chaa = $cha->where("a_keyword = 274")->select(); foreach($chaa as &$v) { $aid = $v['a_id']; $aa = $cha->where("laiyuan = $aid")->select(); //判断是否有二级菜单 if(empty($aa)) { $v['shao']=""; } else{ $v['shao']= $aa; } //dump($aa); } $this->assign('chaa',$chaa); $this->display('Wxh:public/25-1index'); } }
Well, the first sql is for first-level navigation, and the second one is for checking. Level navigation,
Look at the front-end code:
<nav class="nav"> <ul class="ul1"> <foreach name="chaa" item="ab"> <li class="li1"> <a href="about.html">{$ab.a_title}</a> <if condition=" $ab['shao'] neq '' "> <ul> <foreach name="ab[ 'shao'] " item="v "> <li> <a href="about.html ">{$v.a_title}</a> </li> </foreach> </ul> <else /> </if> </li> </foreach> </ul> </nav>
Here 7fa7336d20eea92e111e45cac9538690 is to determine whether Empty
Highlight:
var pathArray = location.pathname;$aa=$("a[href='"+pathArray+"']").$dd.addClass("current");
These two lines of code can handle most navigation highlighting.
Use when encountering special needs: you can get his parent Level: use parents
<script type="text/javascript">var pathArray = location.pathname; $("a[href='"+pathArray+"']").parents('li').addClass("current"); </script>
The above is the detailed content of Code examples on secondary navigation and highlighting in ThinkPhp3.2. For more information, please follow other related articles on the PHP Chinese website!