Home  >  Article  >  Backend Development  >  Code examples on secondary navigation and highlighting in ThinkPhp3.2

Code examples on secondary navigation and highlighting in ThinkPhp3.2

黄舟
黄舟Original
2018-05-19 16:19:251885browse

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(&#39;article&#39;);
        $chaa = $cha->where("a_keyword = 274")->select();

        foreach($chaa as &$v)
        {

            $aid = $v[&#39;a_id&#39;];

      $aa =  $cha->where("laiyuan = $aid")->select();

            //判断是否有二级菜单

            if(empty($aa))
            {
                $v[&#39;shao&#39;]="";
            }
            else{
                           $v[&#39;shao&#39;]= $aa;

            }

//dump($aa);
        }
        $this->assign(&#39;chaa&#39;,$chaa);



        $this->display(&#39;Wxh:public/25-1index&#39;);
    }



}

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[&#39;shao&#39;]  neq &#39;&#39; ">
                                            <ul>

                                                <foreach name="ab[ &#39;shao&#39;] " 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=&#39;"+pathArray+"&#39;]").$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=&#39;"+pathArray+"&#39;]").parents(&#39;li&#39;).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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn