Have nothing to do, take notes
The realization of the second level navigation, is a two-level linkage, um
First look at the database, I like to use a table, the table is more than fun
Second-class code to take the first-class navigation code on the line, do a simple chestnut;
Code section:
Look at the controller, big head in this:
<?phpnamespace 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 (); Determine if there is a level two menu 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 the second level of navigation, which is the level two navigation,
Look at the front-end code:
<nav class= "NAV" > <ul class= "ul1" > <foreach n Ame= "Chaa" item= "AB" > <li class= "Li1" > <a href= "about.html" >{$ab .a_title}</a> <if condition= "$ab [' Shao '] Neq "> <ul> <fore Ach name= "ab[' Shao '" item= "V" > <li> <a href= "about.html" >{$v .a_title}</a> </li> </foreach> </ul> <else/> </if> </li> </foreach> </ul> </nav>
Here's <if condition= "$ab [' Shao '] neq '" > is to determine if it is empty
Highlight:
var patharray = location.pathname; $aa =$ ("a[href=" "+patharray+" '] "). $dd. AddClass (" current ");
These two lines of code can handle most of the navigation highlighting,
Encountered special need to use: can be taken to his parent: with parents
<script type= "Text/javascript" >var Patharray = location.pathname;$ ("a[href=" "+patharray+" '] "). Parents (' Li '). AddClass ("current");</script>