[英]Bootstrap dropdown nav only working with current page in dynamic navigation
我在學習PHP,SQL等時建立了一個網站。我現在嘗試在原始頁面上進行構建,並且在標准導航中一切正常,當我嘗試添加引導導航欄時,下拉框僅出現在當前頁面上上。 在index.php
沒有任何下拉列表有效。 該頁面在后端具有CMS,而我試圖使該頁面的公共方面看起來更好,並確保無論數據庫中有多少新頁面或主題,css都適用於所有內容。
任何幫助將不勝感激!
額外的問題:我還希望克拉僅在“主題”具有多個關聯頁面時出現,如果可能的話,我也無法弄清楚該怎么做。 例如:因此,在單擊主題時,您會單擊該主題的唯一頁面,但是,如果頁面多於一頁,則會顯示一個“ carrat”,然后從下拉菜單中選擇所需的頁面
我的導航是一項功能,並且僅在導致我最初出現問題的CSS上能正常工作。
function public_navigation($subject_array, $page_array) {
$output = "<nav class=\"navbar navbar-default\">";
$output .= "<div class=\"container-fluid\">";
$output .= "<div class=\"navbar-header\">";
$output .= "<button type=\"button\" class=\"navbar-toggle\" data-toggle=\"collapse\" data-target=\"#myNavbar\">";
$output .= "<span class=\"icon-bar\"></span>";
$output .= "<span class=\"icon-bar\"></span>";
$output .= "<span class=\"icon-bar\"></span>";
$output .= "</button>";
$output .= "<a class=\"navbar-brand\" href=\"index.php\">Company</a>";
$output .= "</div>";
$output .= "<div class=\"collapse navbar-collapse\" id=\"myNavbar\">";
$output .= "<ul class=\"nav navbar-nav\">";
$subject_set = find_all_subjects();
while($subject = mysqli_fetch_assoc($subject_set)) {
$output .= "<li class=\"dropdown\">";
$output .= "<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"index.php?subject=";
$output .= urlencode($subject["id"]);
$output .= "\">";
$output .= htmlentities($subject["menu_name"]);
$output .= "<span class=\"caret\"></span></a>";
if ($subject_array["id"] == $subject["id"] ||
$page_array["subject_id"] == $subject["id"]) {
$page_set = find_pages_for_subject($subject["id"]);
$output .= "<ul class=\"dropdown-menu\">";
while($page = mysqli_fetch_assoc($page_set)) {
$output .= "<li>";
$output .= "<a href=\"index.php?page=";
$output .= urlencode($page["id"]);
$output .= "\">";
$output .= htmlentities($page["menu_name"]);
$output .= "</a></li>";
}
$output .= "</ul>";
mysqli_free_result($page_set);
}
$output .= "</li>"; // end of the subject li
}
mysqli_free_result($subject_set);
$output .= "</ul></div></div></nav>";
return $output;
}
編輯: 這是菜單看起來像
但是,如果您單擊其他標題中的任何一個,則不會顯示任何下拉框,並且如果在帶有通用歡迎頁面的index.php上,則所有菜單都沒有下拉框,或者您可以導航到它們
在不知道$ subject_array和$ page_array中傳遞了什么的情況下,很難說出失敗的原因,但是幾乎可以肯定,問題出現在您的if語句中:
if ($subject_array["id"] == $subject["id"] || $page_array["subject_id"] == $subject["id"]) {
看起來您根本不需要if語句,因為您希望每次都獲取給定主題的頁面。 因此,我建議您嘗試刪除if並查看得到的結果:
$output .= "<span class=\"caret\"></span></a>";
$page_set = find_pages_for_subject($subject["id"]);
$output .= "<ul class=\"dropdown-menu\">";
while($page = mysqli_fetch_assoc($page_set)) {
$output .= "<li>";
$output .= "<a href=\"index.php?page=";
$output .= urlencode($page["id"]);
$output .= "\">";
$output .= htmlentities($page["menu_name"]);
$output .= "</a></li>";
}
$output .= "</ul>";
mysqli_free_result($page_set);
$output .= "</li>"; // end of the subject li
現在,您將具有每個主題的下拉菜單,並且只需要一個小的if語句即可添加一些額外的CSS類或用於顯示當前選擇的主題的主題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.