Forum Moderators: coopster

Message Too Old, No Replies

Displaying 'active' class for lists within an include

         

mr_nabo

9:59 am on Jan 24, 2008 (gmt 0)

10+ Year Member



Hi,

This has been something that I can't figure out despite making a few sites using includes.

I want to give a list item (for general navigation) and active class when I am on that page. Because I use an include for my navigation to make life easier updating pages, I can't specify an active class for each list item that is active.

I've resorted to trying to read the url for the page name and using an if-else statement to display the class in the list item if the page name matches the link of the list item (does that make sense? i.e. if url is ...page1.php, then list item with page1.php in it displays an active class)

Is there a better way than this?

Cheers

whoisgregg

3:14 pm on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



read the url for the page name and using an if-else statement

The details of the implementation vary, but this is often how this is accomplished. Are you having trouble getting your nav script working? Or was there something more you want the script to do than just highlight a matching item?

mr_nabo

4:23 pm on Jan 24, 2008 (gmt 0)

10+ Year Member



Thanks for getting back to me. Is there an example (or maybe a few examples?) of how people do this as I'm sure my way is less than adequate being a beginner php coder.

At the moment, I'm just piecing together the knowledge I know and trying to be creative, but I'm sure there's a standard way out there of doing these types things...

coopster

1:13 am on Jan 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Like this?
Hiding hyperlinks for page displayed [webmasterworld.com]