Jump to content

highlighting users location from a generic menu file.


mathewjenkinson

Recommended Posts

ive got a vertical menu system stored in a mysql db thats called when a page loads.

is there a way I can use a tag or parameter to highlight what page you are on?

at present im using:

 

<ul>
<li><a href="#" tabindex="1">What We Do</a></li>
<li><div class="active"><a href="#" tabindex="2">Education</a></div></li>
<li><a href="#" tabindex="3">Research</a></li>
<li><a href="#" tabindex="4">Grants and Awards</a></li>
<li><a href="#" tabindex="5">National Societies</a></li>
<li><a href="#" tabindex="6">EONS Newsletter</a></li>
<li><a href="#" tabindex="7">News</a></li>
<li><a href="#" tabindex="8">Events</a></li>
</ul>

 

with the div class identifying what page the user is presently on. This means putting the whole menu system into each page where it would be easier to load from a single file. Would it still be possible to highlight what page the user is on?

Sure, just do something like this for each item in the menu

 


<li><?php if($_SEVER['php_self']=="THE FILENAME HERE"){echo "<div class='active'><a href='#' tabindex='1'>What We Do</a></div>";}else{echo "<a href='#' tabindex='1'>What We Do</a>";}</li>

 

$_SERVER['php_self'] contains the file the user currently has active, so for each item on the menu you just check the filename against $_SERVER['php_self'].  If $_SERVER['php_self'] equals the file specified for the menu item, highlight it, otherwise don't.

 

I hope I'm making sense and I hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.