<?php
// Select all entries from the menu table
$sql1 = $pardConfig->prepare("SELECT id, menu_title, menu_link, parent FROM pard_menu ORDER BY parent, sort, menu_title");
// Create a multidimensional array to conatin a list of items and parents
$sql1->execute();
$menu = array(
'items' => array(),
'parents' => array()
);
// Builds the array lists with data from the menu table
while ($items = $sql1->fetch()) {
// Creates entry into items array with current menu item id ie. $menu['items'][1]
$menu['items'][$items['id']] = $items;
// Creates entry into parents array. Parents array contains a list of all items with children
$menu['parents'][$items['parent']][] = $items['id'];
}
// Menu builder function, parentId 0 is the root
function buildMenu($pardConfig, $parent, $menu)
{
$html = "";
if (isset($menu['parents'][$parent])) {
$html .= "
<ul>\n";
foreach ($menu['parents'][$parent] as $itemId) {
if (!isset($menu['parents'][$itemId])) {
$html .= "<li>\n <a href='" . $menu['items'][$itemId]['menu_link'] . "'>" . $menu['items'][$itemId]['menu_title'] . "</a>\n</li> \n";
}
if (isset($menu['parents'][$itemId])) {
$html .= "
<li>\n <a href='" . $menu['items'][$itemId]['menu_link'] . "'>" . $menu['items'][$itemId]['menu_title'] . "</a> \n";
$html .= buildMenu($pardConfig, $itemId, $menu);
$html .= "</li> \n";
}
}
$html .= "</ul> \n";
}
return $html;
}
echo buildMenu($pardConfig, 0, $menu);
?>
上面的代碼是一個包含PHP代碼來創建具有多級子menus.I動態菜單已預定義了類此...分類動態菜單添加特定類PHP的
- 主
ul
(第一UL)我有.nav
類 - 對於其中具有第一級子菜單任何
li
我有.dropdown
類鋰 - 此外,對於第二步驟i具有
.dropdown-menu
類ul
elemnts 它具有作爲li
- 父元素,我有一個
.dropdown-submenu
類3級子菜單
所以我想修改我的代碼添加這些4個setps呢?任何幫助,將不勝感激 ?
我將使用bootsramp菜單API此
這種方法我用jQuery做這樣bellow.but這不是很好的100%..
$(".nav-collapse").find("ul").first().addClass("nav");
$(".nav-collapse").find("li").has("ul").addClass("nav");
$(".nav").find("li:has(ul) a").attr("data-toggle", "dropdown");
$('ul').filter(function() {
return $(this).parent().is('li')
}).addClass('dropdown-menu');
$(".nav").find("li ul li").addClass("dropdown-submenu");
$('.dropdown-toggle').dropdown();
});
那麼究竟什麼是你與你的代碼有問題嗎? –
需要這樣的類添加到。它是很難做到這一點對我來說 – underscore