Navigation bar current class change php include
This question already has an answer here:
尝试这个 :
<?php
$page = "";
if(isset($_GET["page"]) && $_GET["page"] != "") {
$page = $_GET["page"];
}
?>
<div class="container">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/womsy/home.php">Womsy</a>
</div>
<ul class="nav navbar-nav">
<li <?php if ($page == "home") { echo "class='active'";} ?>><a href="?page=home">Home</a></li>
<li <?php if ($page == "blog") { echo "class='active'";} ?>><a href="?page=blog">Blog</a></li>
<li <?php if ($page == "projects") { echo "class='active'";} ?>><a href="?page=projects">Projects</a></li>
<li <?php if ($page == "contact") { echo "class='active'";} ?>><a href="?page=contact">Contact</a></li>
<li <?php if ($page == "about") { echo "class='active'";} ?>><a href="?page=about">About</a></li>
</ul>
</div>
</nav>
You need fix your if block
if ($page = "home")
to
if ($page == "home")
i think you have a error
<?php if ($page = "home") {class=active;} else {echo "Failed to load active class."} ?>
should be
<?php if ($page == "home") {class=active;} else {echo "Failed to load active class."} ?>
链接地址: http://www.djcxy.com/p/58474.html
上一篇: 无法使用PHP将启动类添加到Bootstrap下拉菜单
下一篇: 导航栏当前类更改php包括