View Full Version : Include navigation formatting help

01-09-2006, 01:01 PM
My first go with PHP!

I have a simple hyperlink navigation panel which is accessed by various content pages via an PHP 'include' statement. I would like to highlight the navigation link of the corresponding page so it looks as though it's pressed down. Ideally, I'd like to do it using CSS.

Can anyone help.
p.s. I would suggest any help is in the form of an idiot's guide?


01-09-2006, 03:13 PM
The way I do this is to get the current page name and then use it to determine which style is applied to the link (and, indeed, remove the anchor so there is no link to the current page).

$url = basename($_SERVER['PHP_SELF']);

That assigns the current page name to the variable $url. Then for each link in your navigation, you can use an if/else statement to show the correct item. For a homepage link in an unordered list, this might look like this:

if ($url == index.php) {
echo '<li class="active">Home</li>';
} else {
echo '<li><a href="index.php">Home</a></li>';

You're then free to style the item corresponding to the page your on however you want using CSS.

- Adam