Advanced Bulleted-List Menu - Menu Layout
(Page 2 of 7 )
The first thing we want to do is layout our menu in a way that is easy to change. I've decided to use a multi-dimensional array for this, and it should be easy to follow considering that an array is laid out just like a bulleted-list.
The array's structure is as follows: Menu Title => Menu Target.
If we want the "target" to be a sub-menu, then the target will simply be another array which follows the same structure, and so on...
<?php // associative array of menu items // menu title => menu target $menu = array('Menu One'=>array('Page One'=>'blist_menu.php?pg=1', 'Page Two'=>'blist_menu.php?pg=2'), 'Menu Two'=>array('Page Three'=>'blist_menu.php?pg=3', 'Page Four'=>'blist_menu.php?pg=4'), 'Menu Three'=>array('Page Five'=>'blist_menu.php?pg=5', 'Menu Four'=>array('Page Six'=>'blist_menu.php?pg=6', 'Page Seven'=>'blist_menu.php?pg=7'))); ?> |
If you want to make sure your menu is laid out right, print_r can be used to display the entire array in a nice, easily readable format.
<?php echo "<pre>"; print_r($menu); echo "</pre>"; ?> |
I saved my menu code in a file called "blist_menu.php" and you can see my script references itself in the "target" sections. Your menu doesn't have to link back to itself, but I do it here because it's easier to read and test. Your menu targets can go anywhere you want them to go, otherwise we'd have a pretty crappy menu wouldn't we?
CAUTION: It is important to note that each menu title and target should have a unique name in order for the "preserve" functionality to work, which we'll discuss next. This should not be a problem in the majority of cases; however, for you code-happy monkeys that want to tweak this menu to list entire directory structures, it might be a problem.
Next: Preserving State Without Cookies >>
More Navigation Usability Articles
More By notepad
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|