<li <?php if (basename($_SERVER['REQUEST_URI'], ".php") == "index"){
  echo 'class="active"';
  }  ?>><a href="index.php">Home</a></li>

On Tuesday, July 31, 2012 11:53:17 PM UTC+10, fled wrote:
>
> Hello to all.
>
> I'm using the navbar to navigate through my site.  From what I see, I need 
> to put the navbar definition on all my pages with the "active class" active 
> on the selected page.  If I'm right, it is redundant...  What I'm trying to 
> do is to create a header.php file which would contain the navbar.  This 
> file would then be included "include("header.php")".  All of this currently 
> works. The only problem I have is, how to activate the List item 
> representing the displayed page?
>
> Here is the code:
>
> =========header.php===========
> <!--NavBar -->
> <div class="navbar navbar-fixed-top">
>   <div class="navbar-inner">
>     <div class="container">
>       <a class="btn btn-navbar" data-toggle="collapse" 
> data-target=".nav-collapse">
>         <span class="icon-bar"></span>
>         <span class="icon-bar"></span>
>         <span class="icon-bar"></span>
>       </a>
>       <a class="brand" href="index.php">Mysite</a>
>       <div class="nav-collapse">
>         <ul id=ul_nav class="nav">
>           <li id=li_home><a href="index.php">Home</a></li>
>           <li id=li_about><a href="about.php">About</a></li>
>           <li id=li_cont><a href="contact.php">Contact</a></li>
>         </ul>
>       </div>
>     </div>
>   </div>
> </div>
> <!--NavBar end -->
>
> ====== about.php =================
> I've tried this in this file without success
>
> <body>
> <?php
> include("_header.php"); 
> ?>
> ...
>
> <!--At the end of the document -->
> <script type="text/javascript">
> $(document).ready(function(){ 
> $('#li_about').addClass('active') ;
> });
> </script>
> </body>
> </html>
> Any help would be greatly appreciated.
>
> Thanks.
>
>

Reply via email to