menu problem

jagguy
jagguy used Ask the Experts™
on
Hi,

The left menu on this website has a color on the link to tell you what page you are on.
I did this using 6 different menus with the desired color on the link. My method is too long.

How do I create just 1 menu and have the menu link show with background color what page you are on?

http://127.0.0.1/hugh/home2.php
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
That link points to your local server - no way we can see that.

Author

Commented:
And this is a problem?

http://www.mymrt.net/hugh/home2.php
Most Valuable Expert 2011
Top Expert 2016

Commented:
What is the method that is too long?  Can you show us what you're concerned about?
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Ok it depends on how you are constructing your site. The way I see it there are two options

1. You use the approach of each page includes a header and a footer above and below the content respectively

2. You use a master template that has header and footer in it and includes the content in the body of the template.

Either way you use a parameter to determine how to style the menu.

Taking your menu as an example
<ul id="vertmenu">
  <li>  <a href="home2.php" class="link11<?php echo ($page=='home2')?' selected'::'';?>">Home</a><!--link1--></li>
  <li> <a href="about.php" class="link2<?php echo ($page=='about')?'selected'::'';?>">About Us </a><!--link2--></li>
  <li> <a href="dye.php" class="link3<?php echo ($page=='dye')?'selected'::'';?>"> Dye Colors</a><!--link3--></li>
  <li> <a href="sustain.php<?php echo ($page=='sustain')?'selected'::'';?>" class="link4">Sustainability  </a><!--link4--></li>
  <li>  <a href="product.php<?php echo ($page=='product')?'selected'::'';?>" class="link5"> Products </a><!--link5--></li>
  <li> <a href="contact.php<?php echo ($page=='contact')?'selected'::'';?>" class="link6">Contact Us</a><!--link6--></li>
</ul>

Open in new window

You will see in the above code to each class I have added the following
<?php echo ($page=='<pagename>')?' selected'::'';?>

Open in new window

I am assuming that $page will be set before the menu and will be set to whatever the page is you are browsing to. This can either be a parameter you define at the top of your page
$page='home2';

Open in new window

If you are using a header / footer approach.
Or you can work it out based on the URL. It does not matter how - all that matters is that $page is set to the pagename of the page you are accessing.

The next step is to create the style for the .selected class to be the hightlight for the menu.
When you load the page and the menu is included the php code will automatically assign the selected class to the menu item for the page you are on - and css will do the rest.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial