PDA

View Full Version : Navigation question - can a php nav link indicate what page is currently being shown?


Jeepers34683
09-24-2002, 03:25 PM
I AM AN EXTREMELY NEW NEWBIE who has searched for the answer to this question. So if it's obvious please forgive me!

Here's the deal. Let's say you have links:

Home
Fred
Betty
Barney

And "Home" is highlighted when you are on the home page. Then you click on "Fred." It highlights, takes you to the Fred page, and remains highlighted. Meanwhile Home is unhighlighted on that page. Basic stuff.

This is easy in regular HTML. But if I want to have a separate file for navigation in PHP, I don't know how to make the menu switch with each page without making a separate PHP nav file for every page - kinda defeating the purpose.

Directions...tutorial...anything that will specifically answer this question in newbie-like, easy terms would be very much appreciated.

Thanks!!! :o

c q
09-28-2002, 04:10 PM
heyy relax !!now thats easy enuff....even for a newbie... thats the magic of php :D

so lets say u got links as u just mentioned...the basic idea is to check the name of the current file with the ones in the navbar...and display it as desired by u. If it matches, it'll display it as plain text, if not, it'll come out as a normal link.
With this u can happily code your own script !!!
or else here's some elementary stuff...modify it according to your needs

/*$workaround is introduced because $PHP_SELF will return something like /home.php, /fred.php etc. */

<?php
function NavElement($link,$txt){
global $PHP_SELF;

$workaround="/".$link;
if ($workaround==$PHP_SELF){
echo("<strong>$txt</strong><br>");
}
else {
echo("<a href=\"$link\">$txt</a><br>");
}
}
?>
<strong>Navbar</strong>
<?php
NavElement("test.php", "home");
NavElement("fred.php", "Fred");
NavElement("betty.php", "Betty");
NavElement("barney.php", "Barney");
?>

enjoyy !

-----------------
www.siyahee.cjb.net (http://siyahee.cjb.net) needs a bigtime rennovation I think !

Jeepers34683
09-28-2002, 04:23 PM
Thank you, CQ! I'll work on it. I really appreciate your taking the time to reply. :cool: