Newbie: Apply Active Class on menu items
Posted: Fri Dec 16, 2011 10:21 am
Hello. I'm desiging a site that uses includes. I want the navigation to show a marker to the user to indicate what page they are on. But, my nav is an include (nav.php) and I've been struggling to get the code right to have the pages work with the include to show the active state. I've tried this:
Then placing this code on the current page:
<?php $current = 1; include('includes/nav.php'); ?>
But I get a parse error:
Parse error: syntax error, unexpected '=' in E:\inetpub\vhosts\mvpainspecialists.com\httpdocs\devphp\includes\nav.php on line 2
Please don't suggest I use $page_name in the LI because there are only 4 nav elements yet approx 15 pages. (Basically my pages fall under the nav categories, but I am not using dropdowns...once the user lands on one of the category pages, they will get a secondary side nav)
Any hints?
Code: Select all
<?php
$active[$current] = “class=active”;
?>
<div id="nav_wrapper">
<div id="nav_container">
<div id="logo">
<img src="images/nav/logo.jpg" alt="Mountain Vista Pain Specialists Logo" width="230" height="90" />
</div>
<ul id="nav">
<li <?php echo $active[1] ?>><a href=”services.php”>Services</a></li>
<li <?php echo $active[2] ?>><a href=”physician.php”>Physician</a></li>
<li <?php echo $active[3] ?>><a href=”patients.php”>Patients</a></li>
<li <?php echo $active[4] ?>><a href=”contact.php”>Contact</a></li>
</ul>
Then placing this code on the current page:
<?php $current = 1; include('includes/nav.php'); ?>
But I get a parse error:
Parse error: syntax error, unexpected '=' in E:\inetpub\vhosts\mvpainspecialists.com\httpdocs\devphp\includes\nav.php on line 2
Please don't suggest I use $page_name in the LI because there are only 4 nav elements yet approx 15 pages. (Basically my pages fall under the nav categories, but I am not using dropdowns...once the user lands on one of the category pages, they will get a secondary side nav)
Any hints?