Dynamically change anchor id based on current page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
antoine
Forum Commoner
Posts: 37
Joined: Thu Jul 10, 2008 1:43 pm

Dynamically change anchor id based on current page.

Post by antoine »

I have a pretty basic website started. However, since I know I will have to add/change/delete certain parts of the menu, I decided to make the menu an included PHP file.

However, I also have set up a "current" id for the anchor tag. Normally it would be easy, and I would just add "<a href="somepage.php" id="current">". However, since it is an included page, I was wondering if I could set it up to, depending on which page you are at, add the id="current" dynamically, using PHP of course.

Would I do this on the menu.php file or somewhere on the page where I call the 'include' function?

Thanks. Any help is appreciated,
Antoine
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Dynamically change anchor id based on current page.

Post by yacahuma »

rememeber that if you include a page , you have access to all the variables declared in the parent page. So you can just assume that a certain variable is defined before including a file

Code: Select all

 
$current_page = 'whatever';
include 'menu.php';
 
then in menu.php you just use the current_page variable
antoine
Forum Commoner
Posts: 37
Joined: Thu Jul 10, 2008 1:43 pm

Re: Dynamically change anchor id based on current page.

Post by antoine »

Thanks!

I had tried that earlier and it didn't work, but I just discovered I used " instead of' '.

Thanks for the help!
Post Reply