Code case for level two navigation and highlighting in ThinkPhp3.2

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.