我試圖在我的網頁上創建導航,但是使用導航欄的php模板使得難以將活動類添加到正確的頁面。使用PHP模板的活動頁面
例如,如果我的PHP文件是如下:
<nav>
<ul>
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Contact</a></li>
</ul>
</nav>
如何給每個頁面類.active
?
我能看到的唯一選擇是在該特定頁面上爲<html>
或<body>
分配一個每個頁面名稱的類。
如果您顯示請求的URL的正確內容,那麼您將有所有信息遍歷導航並將該類添加到正確的項目中。你使用什麼模板/框架? – Stefan
您可以使用每個頁面唯一的PHP變量。像,$ pageTitleIs ='ThisPage';然後用這個來告訴你在哪個頁面上。 – durbnpoisn
在詢問之前嘗試搜索。 http://stackoverflow.com/questions/6741977/php-navigation-menu-and-active-page-styling?rq=1 http://stackoverflow.com/questions/13336200/add-class-active-to-active -page-using-php?rq = 1 http://stackoverflow.com/questions/18244449/show-active-navigation-for-current-page-with-php?rq=1 http://stackoverflow.com/questions/19387470/php-based-on-which-page-im-on-change-the-active-class?rq = 1 http://stackoverflow.com/questions/19463730/global-navigation-with-active-selector- php?rq = 1 http://stackoverflow.com/questions/21254404/class-active-when-on-page-using-php?rq=1 –