I don't know if this will be of any use to anyone, but I wrote it a while back and it's been handy on a few different projects. There are most likely better written examples on the net, but I thought i'd share it anyways.
Normally if you are highlighting the "active" navigation link for the current page (e.g. http://www.alistapart.com/articles/), you can't have the navigation menu as a seperate include because it needs to be slightly different for each page. (Having it as an include is handy because it means that you only need to edit one file should the navigation need updating).
Basically the code below allows you to have only one navigation list which you can include (using php) in your pages, whilst still retaining the "active" functionality.
And then in each page you need to include the menu:
Feel free to point out any flaws or improvements.
Normally if you are highlighting the "active" navigation link for the current page (e.g. http://www.alistapart.com/articles/), you can't have the navigation menu as a seperate include because it needs to be slightly different for each page. (Having it as an include is handy because it means that you only need to edit one file should the navigation need updating).
Basically the code below allows you to have only one navigation list which you can include (using php) in your pages, whilst still retaining the "active" functionality.
Code:
<?php
// set up the default navigation
$nav1 = '<li><a href="addEnquiry.php">Add Enquiry</a></li>';
$nav2 = '<li><a href="viewEnquiries.php">View/Edit Enquiries</a></li>';
$nav3 = '<li><a href="createReport.php">Create Report</a></li>';
$nav4 = '<li><a href="todaysCallbacks.php">Today\'s Callbacks</a></li>';
// markup the correct list item as active - $thisPage is provided by the page which is including this file
switch ($thisPage)
{
case 'ELTS :: Add Phone Enquiry':
$nav1 = '<li><a href="#" id="current">Add Enquiry</a></li>';
break;
case 'ELTS :: View/Edit Phone Enquiries':
$nav2 = '<li><a href="#" id="current">View/Edit Enquiries</a></li>';
break;
case 'ELTS :: Create Report':
$nav3 = '<li><a href="#" id="current">Create Report</a></li>';
break;
case 'ELTS :: Today\'s Callbacks':
$nav4 = '<li><a href="#" id="current">Today\'s Callbacks</a></li>';
break;
}
// draw out the modified navbar with correct section active
echo '<ul id="ELTSNav">';
echo $nav1;
echo $nav2;
echo $nav3;
echo $nav4;
echo '</ul>';
?>
And then in each page you need to include the menu:
Code:
<?php
// the name of the current page
$thisPage = "ELTS :: Add Phone Enquiry";
require_once('navBar.php');
?>
Feel free to point out any flaws or improvements.