Need help with using selected class with includes

Hi guys,

I’m using PHP includes for my site and in the header include I have my main navigation - so it’s drawn in to whatever page the user goes to from header.php.

I want to have a ‘selected’ <li> class for the navigation so the relevant button is highlighted depending on which page/section the user is on…

How would I go about implementing it into header.php - is there a way I can put a bit of PHP in each of the pages to make the appropiate <li> in header.php use the ‘selected’ class?

Thank you and I hope to hear from you.

SM

[FONT=Verdana]You mean something like this?

<?php $currentPage =  basename($_SERVER['SCRIPT_NAME']);
ini_set('display_errors', false);
?>

<div id="nav">
<ul>
<li <?php if ($currentPage == 'index.php') {echo 'class="current"';} ?>><a href="index.php">Home</a></li>
<li <?php if ($currentPage == 'foo.php') {echo 'class="current"';} ?>><a href="design.php">Foo</a></li>
<li <?php if ($currentPage == 'bar.php') {echo 'class="current"';} ?>><a href="standards.php">Bar</a></li>
<li <?php if ($currentPage == 'contact.php') {echo 'class="current"';} ?>><a href="contact.php">Contact Me</a></li>
</ul>	
</div><!-- End nav -->

[/FONT]

Yes, exactly that!!!

Thank you so much, top shooter!! :slight_smile:

SM

Great, glad I could help. As this turned out to be a PHP issue, rather than a CSS one, I’ll move the thread to the PHP forum, for the benefit of anybody else with a similar question. :slight_smile: