ho trovato questo http://www.zend.com/codex.php?id=1470&single=1 interessante, solo che in questo modo non riesco a gestire alcune cose. Questo script prevede che ci siano solo la descrizione del link ed il nome della pagina, io dovrei almeno avere anche il titolo, e un campo id che mi definisce quello specifico link per includere via css magari una mini-immagine.
Inoltre vorrei organizzare le pagine su più directory, e non mettere tutto sulla web root, quindi nella generazione ricorsiva dovrei poter sapere a quale livello mi trovo, altrimenti come posso linkare le pagine che sono negli altri livelli?
poi tra l'altro, il menu è concettualmente sbagliato, perchè chiude il campo ul ogni volta che non c'è un
sotto menu.
Riporto lo script
Codice PHP:
<?php
/*
---------------------------
Author: Vardhan
Date: March 03rd, 2005
---------------------------
A navigation menu displayed using a recursive menu.
Comments are not used to explain the code, so insted I will explain it here.
$menu is an array with the menu.
everytime you create another dimension on $menu, it creates a submenu.
for example, the $menu array below has 2 submenus under tutorials: php, java
PHP and Java both have submenus under them: Language, Databases, Networking, CLI, Other
If the value of a key in $menu is an array(), it will create a submenu.
If its not, it'll create a link, where the link address is the value.
diplay_menu() takes 1 argument: $m
$m is an array of all the items and links an array has.
In this case, our array is the $menu
Everytime there is an array() in the $menu, it creates a <ul> inside the[*] to make a sub menu, and calls it self (recursitivity) passing the array.
This keeps going on and on until all array()s are encountered.
Sorry if the explanation above is unclear.
Hopeful, my code is clear enough to understand.
You can use CSS to edit any line indentions.
You can use javascript to expand/collapse the menus.
*/
$menu=array();
$menu["home"]="#";
$menu["tutorials"]=array();
$menu["tutorials"]["php"]=array();
$menu["tutorials"]["php"]["Language"]="#";
$menu["tutorials"]["php"]["Databases"]="#";
$menu["tutorials"]["php"]["Networking"]="#";
$menu["tutorials"]["php"]["CLI"]="#";
$menu["tutorials"]["php"]["Other"]="#";
$menu["tutorials"]["java"]=array();
$menu["tutorials"]["java"]["Language"]="#";
$menu["tutorials"]["java"]["Databases"]="#";
$menu["tutorials"]["java"]["Networking"]="#";
$menu["tutorials"]["java"]["CLI"]="#";
$menu["tutorials"]["java"]["Other"]="#";
$menu["forums"]="#";
function display_menu($m) {
foreach ($m as $section => $link) {
if (!is_array($link))
echo "<ul>[*][url='{$link}']{$section}[/url][/list]";
else {
echo "<ul>[*]{$section}";
display_menu($link);
echo '[/list]';
} // end of else
} // end of foreach loop
} // end of function
display_menu($menu);
?>