导航栏当前类更改php包括

这个问题在这里已经有了答案:

  • 3个不同等于4个答案

  • 尝试这个 :

    <?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>
    


    你需要修复你的if块

    if ($page = "home")
    

    if ($page == "home")
    

    我认为你有一个错误

    <?php if ($page = "home") {class=active;} else {echo "Failed to load active class."} ?>
    

    应该

    <?php if ($page == "home") {class=active;} else {echo "Failed to load active class."} ?>
    
    链接地址: http://www.djcxy.com/p/58473.html

    上一篇: Navigation bar current class change php include

    下一篇: PHP executing header:location regardless IF statement parameters