Bij voorbaat excuses voor het breed schalen van het forum.
Onderstaande functie doorloopt de $nodes array en bouwt een navigatie menu. Dit werkt opzich goed.
Hierboven roep ik de functie aan met als actieve node, de node met id 110. Het menuutje ziet er dan als volgt uit:
Ik zit met twee problemen:
• het openen en sluiten van <li> gaat niet altijd goed
• regel 17 moet "contact" in plaats van "product/contact" zijn
Wie kan mij op weg helpen met deze problemen? Het tweede probleem heb ik geprobeerd op te lossen door "$href.= $item['alias'].'/'; " op verschillende plaatsen binnen de functie te zetten, maar dit mag niet baten. Bij het openen en sluiten van <li> zie ik het probleem helemaal niet: volgens mij zou het zo moeten werken...
Onderstaande functie doorloopt de $nodes array en bouwt een navigatie menu. Dit werkt opzich goed.
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| $nodes[1] = Array('pid'=> 0, 'title'=> 'Home', 'alias'=> '', 'status'=> 1, 'innav'=> 1); $nodes[93] = Array('pid'=> 1, 'title'=> 'Over Ons', 'alias'=> 'over', 'status'=> 1, 'innav'=> 1); $nodes[101] = Array('pid'=> 1, 'title'=> 'Nieuws', 'alias'=> 'nieuws', 'status'=> 1, 'innav'=> 1); $nodes[95] = Array('pid'=> 1, 'title'=> 'Product', 'alias'=> 'product', 'status'=> 1, 'innav'=> 1); $nodes[100] = Array('pid'=> 1, 'title'=> 'Handleiding', 'alias'=> 'handleiding', 'status'=> 1, 'innav'=> 0); $nodes[96] = Array('pid'=> 1, 'title'=> 'Contact', 'alias'=> 'contact', 'status'=> 1, 'innav'=> 1); $nodes[104] = Array('pid'=> 1, 'title'=> 'Gastenboek', 'alias'=> 'gastenboek', 'status'=> 0, 'innav'=> 1); $nodes[103] = Array('pid'=> 1, 'title'=> 'Voorwaarden', 'alias'=> 'voorwaarden', 'status'=> 0, 'innav'=> 1); $nodes[97] = Array('pid'=> 95, 'title'=> 'Overzicht', 'alias'=> 'overzicht', 'status'=> 1, 'innav'=> 1); $nodes[99] = Array('pid'=> 95, 'title'=> 'Tekstverwerker', 'alias'=> 'editor', 'status'=> 1, 'innav'=> 1); $nodes[98] = Array('pid'=> 95, 'title'=> 'Sjablonen', 'alias'=> 'templates', 'status'=> 1, 'innav'=> 1); $nodes[110] = Array('pid'=> 98, 'title'=> 'Testpagina', 'alias'=> 'test', 'status'=> 1, 'innav'=> 1); function buildMenu($menuItems, $activeItem, $curItem=1, $depth=0, $href=NULL) { static $output; $unfoldItems = array($activeItem); while ($unfoldItems[count($unfoldItems)-1] != 0) $unfoldItems[] = $menuItems[$unfoldItems[count($unfoldItems)-1]]['pid']; $first = true; foreach ($menuItems as $itemKey=>$item) { if ($item['pid'] == $curItem) { if ($first) { $output.= '<ul>'; $first = false; } if ($item['status'] == 1 and $item['innav'] == 1) { if ($activeItem == $itemKey) { $output.= '<li class="on"><a href="'.$href.'">'.$item['title'].'</a>'; } else { $output.= '<li class="off"><a href="'.$href.'">'.$item['title'].'</a>'; } } if (in_array($itemKey, $unfoldItems)) { $href.= $item['alias'].'/'; buildMenu($menuItems, $activeItem, $itemKey, $depth + 1, $href); } $output.= '</li>'; } } if (!$first) $output.= '</ul>'; return '<div id="navcontainer">'.$output.'</div>'; } buildMenu($menuItems, 110); |
Hierboven roep ik de functie aan met als actieve node, de node met id 110. Het menuutje ziet er dan als volgt uit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <div id="navcontainer"> <ul> <li class="off"><a href="over">Over Ons</a></li> <li class="off"><a href="nieuws">Nieuws</a></li> <li class="off"><a href="product">Product</a> <ul> <li class="off"><a href="product/overzicht">Overzicht</a></li> <li class="off"><a href="product/editor">Tekstverwerker</a></li> <li class="off"><a href="product/templates">Sjablonen</a> <ul> <li class="on"><a href="product/templates/test">Testpagina</a></li> </ul> </li> </ul> </li> </li> <li class="off"><a href="product/contact">Contact</a></li> </li> </li> </ul> </div> |
Ik zit met twee problemen:
• het openen en sluiten van <li> gaat niet altijd goed
• regel 17 moet "contact" in plaats van "product/contact" zijn
Wie kan mij op weg helpen met deze problemen? Het tweede probleem heb ik geprobeerd op te lossen door "$href.= $item['alias'].'/'; " op verschillende plaatsen binnen de functie te zetten, maar dit mag niet baten. Bij het openen en sluiten van <li> zie ik het probleem helemaal niet: volgens mij zou het zo moeten werken...
[ Voor 54% gewijzigd door Reveller op 23-11-2004 22:05 ]
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."