[web-tips > smart-menu]

Smart Menu

So, you want a self-aware menu -- something that will not permit the user to reload the current page. Well... it's very easy with a php solution.

Simply do three things:

  • 1. Place the following navigation code (with your links) in your web pages.
										
<ul>
	<li><a <?php menu("index.php");?> > Home</a></li>
	<li><a <?php menu("web-tips.php");?> > Web Tips</a></li>
	<li><a <?php menu("freeware.php");?> > Freeware</<></li>
	<li><a <?php menu("fb-code.php");?> > FB-Code</a></li>
	<li><a <?php menu("books.php");?> > Books</a></li>
	<li><a <?php menu("resume.php");?> > Resume</a></li>
	<li><a <?php menu("contact.php");?> > Contact</a></li>
</ul>
  • 2. Place the following helper php code somewhere in your web page (i.e., bottom).
			
<?php
	function menu($a)
		{
		$u = basename($_SERVER['PHP_SELF']);
		if ($u==$a)
			{
			echo("");
			}
		else
			{
			echo("href=\"http://yourdomain.com/$a\"");
			}		
		
		}
?>

  • 3. Change your ".html" suffix to ".php".

What does this do?

The php suffix makes the php interpreter read the file and execute the code. Your web page will work the same as before except it will now process the embedded php code.

The code simply takes a php call ($_SERVER['PHP_SELF']) and compares it to the following string. If a match is made, then it shows just the title, and if it doesn't, then it makes it a link.

This technique validates under both HTML 4.01 and CSS.

Enjoy.

tedd...