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?
left nav help - PLEASE
Moderator: General Moderators
If I was doing something along these lines, I would code it like this:
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.
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ї"PHP_SELF"]); /* splits the path to this file
into an array. e.g. this file is /php/play.php
so it returns $current_dirї0] = ""
$current_dirї1] = "php"
$current_dirї2] = "play.php" */
$current_dir = $current_dirї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)
{
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";
}
?>This is probably not the most concise way of doing this but it would work, and be clear when you go back later.