Change link color when on certain 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
nado
Forum Newbie
Posts: 20
Joined: Tue Aug 29, 2006 3:47 am

Change link color when on certain page?

Post by nado »

hi

I'm new to PHP...

I have a simple menu (home, about, newsletter etc) which are in the header.php file and included in each page.

Basically what I want to do is that when the user is on the "About" page the menu "About" link will have a background color to indicate that they are on that page (and the same for other pages).

What php code does this?

thanks
nathan
User avatar
darodesign
Forum Newbie
Posts: 19
Joined: Mon Aug 28, 2006 8:58 am
Location: Berlin
Contact:

Post by darodesign »

Assign a var like $pageName, and every Page should assign a value like index, or board, or impress.

And in the header File ( at your Menü Button ) you can do an easy if construct, e.g. if($pageName == "index") echo 'style="color:#FFFFFF"'; else echo 'style="color:#000000"';

Regards
nado
Forum Newbie
Posts: 20
Joined: Tue Aug 29, 2006 3:47 am

Post by nado »

Is there a better way to do it?

As I'd have to copy that code and do one for index, about, newsletter etc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use CSS. Give the body a class that's individual to the various areas you wish to customize per page.

Code: Select all

body.about div.submenu
{
  background-color: green;
}

body.index div.submenu
{
  background-color: orange;
}
nado
Forum Newbie
Posts: 20
Joined: Tue Aug 29, 2006 3:47 am

Post by nado »

Thanks guys, I managed to get it sorted here: http://www.sitepoint.com/forums/showthr ... ?p=3013477
Post Reply