Jump to content

Select navigation on include file.


ttmt

Recommended Posts

 

Selected navigation on include file.

 

Hi all

 

I can't think how to do this or even if it's possible so I'm hoping someone can help.

 

I have a simple example here to illustrate.

 

http://www.ttmt.org.uk/three.php

 

It's just four linked pages with a heading and a navigation. The navigation has an id="selected" in the <a> tag for that page that changes the color of that link to show you are on that page - very basic.

 

I wanted the put the navigation on the pages with an include file.

 

<?php
include("php/includes/nav.php");
?>

 

and have the code for the nav in nav.php

 

nav.php

<ul id="nav">
  <li><a href="index.php">Home</a></li>
  <li><a href="one.php">One</a></li>
  <li><a href="two.php">Two</a></li>
  <li><a href="three.php">Three</a></li>
</ul>

 

My problem is how can I add the id="selected" to the different links for the different pages if I'm including the navigation code?

 

Hope this makes sense and someone can help. Any help would be greatly appreciated.

Link to comment
Share on other sites

you need to know what page you are on.

 

i wouldn't do it this particular way (i would use a tiny function) but as its only 4 pages, put this above the include statement somewhere on the three.php page.

 

<?php $page = 'three'; ?>

and in your nav include:

<ul id="nav">
  <li><a <?php if($page == 'three') echo 'id="selected"';?> href="index.php">Home</a></li>
  <li><a href="one.php">One</a></li>
  <li><a href="two.php">Two</a></li>
  <li><a href="three.php">Three</a></li>
</ul>

Link to comment
Share on other sites

Could use a bit of JQuery to change the css.

 

<?php 

    if(isset($_GET['id'])) {
       
         $id = $_GET['id'];

         if($id = "home") {
              echo '<Script type="text/javascript">"$(''#IdorClassName).css('color','#666')</script>';
         }

          //and so on...
?>

 

This can be reused then

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.