ThinkCMF-首页Nav部分菜单配置详解

时间:2023-03-08 15:06:44
ThinkCMF-首页Nav部分菜单配置详解

Nav菜单代码放在了 /themes/simplebootx/Public/nav.html

具体代码:

<?php
$effected_id="main-menu";
$filetpl="<a href='\$href' target='\$target'>\$label</a>";
$foldertpl="<a href='\$href' target='\$target' class='dropdown-toggle' data-toggle='dropdown'>\$label <b class='caret'></b></a>";
$ul_class="dropdown-menu" ;
$li_class="" ;
$style="nav";
$showlevel=6;
$dropdown='dropdown';
echo sp_get_menu("main",$effected_id,$filetpl,$foldertpl,$ul_class,$li_class,$style,$showlevel,$dropdown);
?>

其中"main"表示要获取菜单分类为主菜单下的所有active为1的菜单

function sp_get_menu($id="main",$effected_id="mainmenu",$filetpl="<span class='file'>\$label</span>",$foldertpl="<span class='folder'>\$label</span>",$ul_class="" ,$li_class="" ,$style="filetree",$showlevel=6,$dropdown='hasChild'){
$navs=F("site_nav_".$id);
if(empty($navs)){
$navs=_sp_get_menu_datas($id);
}
import("Tree");
$tree = new \Tree();
$tree->init($navs);
return $tree->get_treeview_menu(0,$effected_id, $filetpl, $foldertpl, $showlevel,$ul_class,$li_class, $style, 1, FALSE, $dropdown);
} function _sp_get_menu_datas($id){
$nav_obj= M("Nav");
$oldid=$id;
$id= intval($id);
$id = empty($id)?"main":$id;
if($id=="main"){
$navcat_obj= M("NavCat");
$main=$navcat_obj->where("active=1")->find(); //挑选出主菜单
$id=$main['navcid'];
} if(empty($id)){
return array();
}
......
}

$effected_id="main-menu" 表示生成的ul元素的id