I currently have some VERY long winded code for the menu I use on my site.
My website
It’s almost 2000 lines long lol. I think I may be able to use a switch but I’ve tried and cannot implement it to work properly.
On each menu when you click a button it stays highlighted, telling the user that they are on that page. The only way I could get this to work was like so…
if($subject == 'art') {
echo '<div id="spacer2"><br></div>';
echo '<div class="idName2" id="menu2">';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=all&listtype='.$listtype.'">All</a>';
echo '<div id="spacer2"><br></div>';
echo '</div>';
echo '<div class="idName3" id="menu3">';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=art&listtype='.$listtype.'">Art</a>';
echo '</div>';
echo '<div class="idName2" id="menu2">';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=biology&listtype='.$listtype.'">Biology</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=english&listtype='.$listtype.'">English</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=chemistry&listtype='.$listtype.'">Chemistry</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=mathematics&listtype='.$listtype.'">Mathematics</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=history&listtype='.$listtype.'">History</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=religion&listtype='.$listtype.'">Religion</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=geography&listtype='.$listtype.'">Geography</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=music&listtype='.$listtype.'">Music</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=philosophy&listtype='.$listtype.'">Philosophy</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=psychology&listtype='.$listtype.'">Psychology</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=economics&listtype='.$listtype.'">Economics</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=sociology&listtype='.$listtype.'">Sociology</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=technology&listtype='.$listtype.'">Technology</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=electronics&listtype='.$listtype.'">Electronics</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=food&listtype='.$listtype.'">Food</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=law&listtype='.$listtype.'">Law</a>';
echo '<a href="browse.php?alphabet='.$alphabet.'&subject=politics&listtype='.$listtype.'">Politics</a>';
echo '</div>';
}
elseif($subject == 'biology') {
and then there’s however many ‘elseifs’ as there are menu items, which ends up totalling to 2000 lines of code which is obviously very inefficient and it also makes it unbelievably time consuming to change anything… can someone point me in the right direction in what I need to do please!
Navigation is always a pain. Here is a simple solution that might help.
Put everything in an array, like this:
Then, you can build all the links based on the current subject:
This is a rather simplistic solution, but it can be extended to create a more complicated menus structure.
Another solution you could look at is Zend_Navigation.
http://framework.zend.com/manual/en/zend.navigation.introduction.html