Page 1 of 1

Change link color when on certain page?

Posted: Tue Aug 29, 2006 3:57 am
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

Posted: Tue Aug 29, 2006 4:09 am
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

Posted: Tue Aug 29, 2006 4:44 am
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

Posted: Tue Aug 29, 2006 9:26 am
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;
}

Posted: Tue Aug 29, 2006 9:46 am
by nado
Thanks guys, I managed to get it sorted here: http://www.sitepoint.com/forums/showthr ... ?p=3013477