Page 1 of 1

left nav help - PLEASE

Posted: Fri Nov 14, 2003 10:30 pm
by bnpagan
I'm very new to php, but here's what I'd like to have happen.

Situation:

/directory1
/directory2
/directory3

When a user is on a page within /directory1 the left nav image for that section would be highlightd (i.e. the rollover state). Likewise if a user is on a page within /directory2 the left nav image would be that rollover state.

Basically

/directory1/*.* the left nav image would change to leftnav_image1.gif
/directory2/*.* the left nav image would change to leftnav_image2.gif
/directory3/*.* the left nav image would change to leftnav_image3.gif

Where *.* is either an HTML or PHP page that is under a category. The rule would apply to all files with their respective directory.

Any thoughts?

Posted: Sat Nov 15, 2003 1:59 am
by Quietus
Have you considered using the explode function on the $_ENV["PATH_INFO"] variable to get the directory of the current file?

Posted: Sat Nov 15, 2003 8:31 am
by bnpagan
No, I'm really new to PHP so I have no idea how I would code this. Thoughts?

Posted: Sat Nov 15, 2003 1:25 pm
by Quietus
If I was doing something along these lines, I would code it like this:

Code: Select all

<?PHP
   $images_folder = "/images/"; //The folder where my images are kept
   $link1_image = "imagedir1.gif"; //The normal image for link1
   $link2_image = "imagedir2.gif"; //The normal image for link2
   $link3_image = "imagedir1.gif"; //The normal image for link3
   $current_dir = explode("/",$_SERVER&#1111;"PHP_SELF"]); /* splits the path to this file
         into an array.  e.g. this file is /php/play.php
         so it returns $current_dir&#1111;0] = ""
                       $current_dir&#1111;1] = "php"
                       $current_dir&#1111;2] = "play.php" */
   $current_dir = $current_dir&#1111;1]; /* To turn the array into the string we need.
         This could be left out with the simplicity of the current example but
         if using a deeper directory structure, this would be the best place to
         concatenate the strings. */
   switch($current_dir)
      &#123;
      case "php": // Your first directory name
         $link1_image = "imagedir1_alt.gif"; //The selected image for link1
         break;
      case "php2":
         $link2_image = "imagedir2_alt.gif";
         break;
      case "php3":
         $link3_image = "imagedir3_alt.gif";
      &#125;
?>
Then I would use the variables $link1_image etc... in my navigation bar.

This is probably not the most concise way of doing this but it would work, and be clear when you go back later.