For my latest project I am wanting to create a menu where each link has it's own unique style.
What I have achieved so far works, each link has it's own style.
However I know this function can be improved because at the moment the 'output' of each correct switch case is the actual menu, obviously each class changing depending on the value of $view.
As you can see the problem is that each menu item needs its own copy of the menu - this will cause major problems when I come to updating the menu....
//Get the page
$view = $_GET["view"];
//Create the function
function activeSwitch($view)
{
switch ($view)
{
case '':
echo "
<li><a href=\"?view=photography\" class=\"hubphotography\">Photography</a></li>
<li><a href=\"?view=web\" class=\"hubweb\">Web</a></li>
";
break;
case "photography":
echo "
<li><a href=\"?view=photography\" class=\"hubphotographyactive\">Photography</a></li>
<li><a href=\"?view=web\" class=\"hubweb\">Web</a></li>
";
break;
case "web":
echo "
<li><a href=\"?view=photography\" class=\"hubphotography\">Photography</a></li>
<li><a href=\"?view=web\" class=\"hubwebactive\">Web</a></li>
";
break;
default:
echo "
<li><a href=\"?view=photography\" class=\"hubphotography\">Photography</a></li>
<li><a href=\"?view=web\" class=\"hubweb\">Web</a></li>
";
break;
}
}
//Call the function
<ul>
<?php activeSwitch($view); ?>
</ul>
As you can see the function has only 2 menu items and is already a nightmare to manage....
Can anyone help me to shrink the function, i'm guessing an include of the menu is the first thing - but I can't work out how to create a variable that can be changed.....
All help appreciated,
Thanks in advance.