帝国CMS如何调用带下拉菜单的导航
帝国CMS建网站时,使用程序自带的菜单标签,可以生成纯A的菜单。
[!--class.menu--]
如果只想调用一级导航,可以使用以下的代码:
<ul class="topnav">
<li class="<?= ($GLOBALS['navclassid'] ? '' : 'current-menu-item') ?>"><a href="[!--news.url--]">网站首页</a></li>
<?php
// 查询一级菜单
$sql = $empire->query("select classid, sonclass, classname, islast, islist from {$dbtbpre}enewsclass where bclassid=0 and showclass=0 order by myorder asc LIMIT 20");
while ($primaryMenu = $empire->fetch($sql)) {
$classUrl = sys_ReturnBqClassname($primaryMenu, 9);
$topClass = '';
$featherClass = explode('|', $class_r[$GLOBALS['navclassid']]['featherclass']);
$topbclassid = $featherClass[1] ? $featherClass[1] : $GLOBALS['navclassid'];
// 判断是否为当前菜单
if ($topbclassid == $primaryMenu['classid']) {
$topClass = 'current-menu-item';
}
?>
<li class="navbar-item <?=$topClass?>"><a href="<?=$classUrl?>"><?=$primaryMenu['classname']?></a></li>
<?php }?>
</ul>
如果想制作带二级菜单,需要显示带下拉功能的导航菜单,使用默认菜单标签是无法实现的。可以使用以下的代码来实现。( LIMIT 20 可以控制数量)
<ul class="topnav">
<li class="<?= ($GLOBALS['navclassid'] ? '' : 'current-menu-item') ?>"><a href="[!--news.url--]">网站首页</a></li>
<?php
// 查询一级菜单
$sql = $empire->query("select classid, sonclass, classname, islast, islist from {$dbtbpre}enewsclass where bclassid=0 and showclass=0 order by myorder asc LIMIT 20");
while ($primaryMenu = $empire->fetch($sql)) {
$classUrl = sys_ReturnBqClassname($primaryMenu, 9);
$topClass = '';
$featherClass = explode('|', $class_r[$GLOBALS['navclassid']]['featherclass']);
$topbclassid = $featherClass[1] ? $featherClass[1] : $GLOBALS['navclassid'];
// 判断是否为当前菜单
if ($topbclassid == $primaryMenu['classid']) {
$topClass = 'current-menu-item';//当前样式
}
//判断是否有二级菜单
if ($primaryMenu['islast'] == 0) {//有下拉
$fuliclass=" ";
$fuaclass=" ";
}else{
$fuliclass=" ";
$fuaclass=" ";
}
?>
<li class="<?=$topClass?> <?=$fuliclass?>"><a class="<?=$fuaclass?>" href="<?=$classUrl?>"><?=$primaryMenu['classname']?></a>
<?php
//判断是否有二级菜单
if ($primaryMenu['islast'] == 0) { ?>
<ul class="sub-menu">
<?
$sql2 = $empire->query("select classid, classname from {$dbtbpre}enewsclass where bclassid={$primaryMenu['classid']} and showclass=0 order by myorder asc");
$subMenuStr = "";
while ($secondaryMenu = $empire->fetch($sql2)) {
$classUrl2 = sys_ReturnBqClassname($secondaryMenu, 9);
?>
<li><a href="<?=$classUrl2?>"><?=$secondaryMenu['classname']?></a></li>
<?
}
?>
</ul>
<?php }
?>
</li>
<?php }?>
</ul>
可以根据自己原代码的类名进行修改,它是自动判断当前一级分类下是否有二级分类,如果有就以下拉的方式来实现展示。