Page 1 of 1

Active Links with PHP

Posted: Fri Apr 18, 2008 7:08 pm
by jessphp
Hi there!

I searched through the forum, but couldn't find any answers to my problem... perhaps I'm searching for it wrong?

I'm using the script found here: http://www.crucialwebhost.com/blog/you- ... avigation/

I've gotten it to work on a few sites of mine, however; when I do mod-rewrite to drop file extensions, I have problems.

Here's the code I usually put right about my "body" tag:

Code: Select all

  
   1. <?
   2. $path = $_SERVER['PHP_SELF'];
   3. $page = basename($path);
   4. $page = basename($path, '.php');
   5. ?>
 
And here's the code I use for the links:

Code: Select all

<a<? if($page == 'one') print ' class="active"'; ?> href="one.php">Page 1</a>
That code works for a file name, other than index.php. See, when I use mod-rewrite - blahblah.com/aboutus/ I can't just put "aboutus" in there, it doesn't work.

Here's a working example of what I'm trying to accomplish:
http://www.otclothing.com/otc-golf/

When you're on the "OTC Golf" page, in the menu, the "OTC Golf" is highlighted in black. I just want that! Any help would be appreciated!

Re: Active Links with PHP

Posted: Mon Apr 21, 2008 6:21 am
by aceconcepts
mod_rewrite re-writes a url based on the server. It typically re-writes url variables according to how you choose to deal with them.

So I would imagine using $_SERVER['PHP_SELF'] will be fetching the unwritten url.