0

我一直在寻找许多方法来使用 PHP 包含函数将导航栏添加到每个页面并使用 PHP 在单击时使选项卡在单击时处于活动状态,并在单击时使用 PHP 使链接处于活动状态,所以这就是我遇到的错误或问题是它显示“和a > 在 home 或任何其他选项卡之前,所以这里是代码...用于主导航栏 PHP 文件...这包含在使用 PHP 包含函数的 html 中:

<body>


<!--Nav Bar-->
            <?php 

                function echoActiveClassIfRequestMatches($requestUri)
                {
                    $current_file_name = basename($_SERVER['REQUEST_URI'], ".php");

                    if ($current_file_name == $requestUri)
                        echo 'class="active"';
                }

            ?>
<div class="navbar navbar-inverse navbar-fixed-top">
     <div class="navbar-inner"> 
             <div class="container" >               
                    <ul class="nav">

                        <a class="brand" class="divider-vertical" href="#"> The Aerosquadron</a>                                          
                        <li <?=echoActiveClassIfRequestMatches("index")?>><a href="index.php">">Home</a></li>                                             
                        <li <?=echoActiveClassIfRequestMatches("Robots_page")?>><a href="Robots_page.php">">Robots</a></li>                                       
                        <li <?=echoActiveClassIfRequestMatches("Sponsors_page")?>><a href="Sponsors_page.php">">Our Sponsors</a></li>    
                        <li <?=echoActiveClassIfRequestMatches("History")?>><a href="History.php">The History</a></li>                                         
                        <li <?=echoActiveClassIfRequestMatches("About_first")?>><a href="About_first.php">">About FIRST</a></li>

                    </ul>
              </div>
          </div>
    </div>          
4

1 回答 1

0

最终的 HTML 部分:

<div class="navbar navbar-inverse navbar-fixed-top">
     <div class="navbar-inner"> 
             <div class="container" >
                    <ul class="nav">

                        <a class="brand" class="divider-vertical" href="#"> The Aerosquadron</a>
                        <li <?=echoActiveClassIfRequestMatches("index")?>><a href="index.php">Home</a></li>                                           
                        <li <?=echoActiveClassIfRequestMatches("Robots_page")?>><a href="Robots_page.php">Robots</a></li>                             
                        <li <?=echoActiveClassIfRequestMatches("Sponsors_page")?>><a href="Sponsors_page.php">Our Sponsors</a></li>    
                        <li <?=echoActiveClassIfRequestMatches("History")?>><a href="History.php">The History</a></li>                                
                        <li <?=echoActiveClassIfRequestMatches("About_first")?>><a href="About_first.php">About FIRST</a></li>

                    </ul>
              </div>
          </div>
    </div>  
于 2013-06-21T08:00:13.863 回答