导航栏中的php class =“active”错误

时间:2013-06-21 07:26:02

标签: php html web

我一直在寻找很多方法,使用PHP包含函数在单击上创建一个选项卡,将导航栏添加到每个页面,如果点击则使用PHP使链接处于活动状态,所以这里是我有错误或问题是它在单词home或任何其他选项卡之前显示“和a>” 所以这里是代码...对于主导航栏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>          

1 个答案:

答案 0 :(得分: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>