1.定义一个变量 来标识所访问的页面
//category_add 标识 category_add.php页面
<?php $current_page = 'category_add';?>
<?php include('inc/left.php');?>
2.模板文件里li标签class="active"
<li <?php if($current_page == 'category_list'){ echo 'class="active"';} ?>><a href="./category_list.php"> <span class="menu-text">栏目列表</span></a></li>
具体代码:
//判断是否已经展开菜单
<?php $menu_categroy = ['category_list','category_add'];?>
<li <?php if(isset($current_page)){ echo in_array($current_page,$menu_categroy)? 'class="active open"':''; }?>>
<a href="#" class="menu-dropdown">
<i class="menu-icon fa fa-cogs"></i>
<span class="menu-text">
栏目管理 </span>
<i class="menu-expand"></i>
</a>
<ul class="submenu">
<li <?php if(isset($current_page)){ if($current_page == 'category_list'){ echo 'class="active"';}} ?>>
<a href="./category_list.php">
<span class="menu-text">
栏目列表 </span>
</a>
</li>
<li <?php if(isset($current_page)){ if($current_page == 'category_add'){ echo 'class="active"';}} ?>>
<a href="./category_add.php">
<span class="menu-text">
栏目添加 </span>
</a>
</li>
</ul>
</li>