I know it sounds confusing but I will try my best to explain what I really mean. Here is part of my css code: .navitab { padding: 4px 8px 4px 8px; margin: 0 0 4px 0; text-decoration: none; letter-spacing: 1px; background: #e0e0e0 url(images/corner.gif) top right no-repeat; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; } .activenavitab { padding: 4px 8px 5px 8px; color: #ffffff; margin: 0 0 5px 0; text-decoration: none; background: #505050 url(images/corner.gif) top right no-repeat; } Code (markup): And my navigation bar at http://ibnuasad.org <div id="navitabs"> <h2 class="hide">Site menu:</h2> <a class="activenavitab" href="index.html">Welcome</a><span class="hide"> | </span> <a class="navitab" href="#">Bio</a><span class="hide"> | </span> <a class="navitab" href="#">Discography</a><span class="hide"> | </span> <a class="navitab" href="#">Downloads</a><span class="hide"> | </span> <a class="navitab" href="#">Photos</a><span class="hide"> | </span> <a class="navitab" href="#">Tour</a><span class="hide"> | </span> <a class="navitab" href="#">Merchandise</a><span class="hide"> | </span> <a class="navitab" href="#">Interviews</a> </div> Code (markup): The navigation code is located at index.html. I want to move the code to a separate file called navigation.php and I would place <?php include("navigation.php") ?> in my index.html file. Here's the problem: I want to make something like when I go to index.html I want the "Welcome" text to use the activenavitab style. But when I go to downloads.html I want the "Downloads" text to use the style activenavitab and make the "Welcome" text use the "navitab" style. Note that I will also be using the code <?php include("navigation.php") ?> in the downloads.html file Anyone knows how to this? Btw, I was not sure where to post this thread cause it involves CSS, HTML and PHP
<?php $l[0][0] = "index.php"; $l[0][1] = "Welcome"; $l[1][0] = "bio.php"; $l[1][1] = "Bio"; $l[2][0] = "discography.php"; $l[2][1] = "Discography"; $l[3][0] = "downloads.php"; $l[3][1] = "Downloads"; $thispage = $_SERVER['SCRIPT_NAME']; $arr = explode("/", $thispage); $page = strtolower($arr[2]); ?> <?php $i = 0; while ($l[$i] != "") { if (strtolower(str_replace(" ", "", $l[$i][0])) == $page) { echo "<a class="activenavitab" href=\"" . $l[$i][0] . "\">" . $l[$i][1] . "</a>"; } else { echo "<a class="navitab" href=\"" . $l[$i][0] . "\">" . $l[$i][1] . "</a>"; } $i++; } ?> Code (markup):
Thanks for the code but the code you gave was showing parse errors so I changed the code a bit into <?php $l[0][0] = "index.html"; $l[0][1] = "Welcome"; $l[1][0] = "bio.html"; $l[1][1] = "Bio"; $l[2][0] = "contact-page.html"; $l[2][1] = "Contact Me"; $l[3][0] = "gallery.html"; $l[3][1] = "Gallery"; $thispage = $_SERVER['SCRIPT_NAME']; $arr = explode("/", $thispage); $page = strtolower($arr[2]); ?> <?php $i = 0; while ($l[$i] != "") { if (strtolower(str_replace(" ", "", $l[$i][0])) == $page) { echo "<a class=\"activenavitab\" href=\"" . $l[$i][0] . "\">" . $l[$i][1] . "</a>"; } else { echo "<a class=\"navitab\" href=\"" . $l[$i][0] . "\">" . $l[$i][1] . "</a>"; } $i++; } ?> PHP: I have placed the code in navigation.php and I have included it in http://ibnuasad.org/bio.html But its not showing the activenavitab style
yeah I forgot to escape the " about the error, try to echo $page, so you know what that var contains maybe change to if (strtolower(str_replace(" ", "", $l[$i][0])) == $page . ".html") { ? anyway, check the $page, with a bit of tweaking it should work
Just like that: echo $page; He is saying put that in your code to see what the value of page is when the script is running. This will print the value out to the webpage and should give you insight into where it is going wrong.
SOLVED! I used the following code: <?php $current_page = explode("/",$_SERVER['SCRIPT_NAME']); $current_page = $current_page[count($current_page) - 1]; function getLocation($string,$current_page) { return ($string == $current_page) ? 'activenavitab' : 'navitab'; } ?> <a class="<?php echo getLocation('index.php',$current_page); ?>" href="index.php">Welcome</a><span class="hide"> | </span> <a class="<?php echo getLocation('bio.php',$current_page); ?>" href="bio.php">Bio</a><span class="hide"> | </span> <a class="<?php echo getLocation('contact-page.php',$current_page); ?>" href="contact-page.php">Contact Me<span class="hide"> | </span> <a class="<?php echo getLocation('gallery.php',$current_page); ?>" href="gallery.php">Gallery</a><span class="hide"> | </span> PHP: Thanks to vaaaska & ClarkF1