array(), 'parents' => array() ); while ($menuItem = mysql_fetch_assoc($result)) { $menuData['items'][$menuItem['page_id']] = $menuItem; $menuData['parents'][$menuItem['parent_id']][] = $menuItem['page_id']; } //echo "
";
//print_r($menuData);
//echo "
"; function buildMenu($parentId, $menuData) { $html = ''; global $path; global $last_parent; global $level; if (isset($menuData['parents'][$parentId])) { $html = '
    '; foreach ($menuData['parents'][$parentId] as $itemId) { $html .="
  • "; //als het een parent in de root betreft if ($menuData['items'][$itemId]['parent_id'] == "0") { $path = $menuData['items'][$itemId]['friendly_url']; $path .= "/"; $last_parent = $menuData['items'][$itemId]['friendly_url']; $last_parent .= "/"; $level = 0; $last_level = 0; } else { //1 niveau dieper if ($menuData['items'][$itemId]['level'] == $level + 1) { $last_parent = $path; $path .= $menuData['items'][$itemId]['friendly_url']; $path .= "/"; $level = $menuData['items'][$itemId]['level']; } //zelfde niveau if ($menuData['items'][$itemId]['level'] == $level) { $path = $last_parent; $path .= $menuData['items'][$itemId]['friendly_url']; $path .= "/"; } //één of meerdere niveaus lager if ($menuData['items'][$itemId]['level'] < $level) { //verschil in niveau $level_difference = $level - $menuData['items'][$itemId]['level']; $level_difference = $level_difference + 1; //verschil in niveaus staat voor het aantal delen dat nu van de last_parent afgehakt moet worden //last_parent in stukken hakken $chops = explode("/", $last_parent); //aantal elementen in $chops $size_of_chops = count($chops); //aantal stukken dat we moeten hebben uit chops $needed_chops = $size_of_chops - $level_difference; //de variabele path eerst leegmaken $path = ""; //lus maken en de pad opnieuw in elkaar zetten for($i=0; $i < $needed_chops; $i++) { $path .= $chops[$i]; $path .= "/"; } //voordat de laatste child erachter wordt gezet maken we nu de last_parent weer aan $last_parent = $path; $path .= $menuData['items'][$itemId]['friendly_url']; $path .= "/"; //$last_parent = $path; $level = $menuData['items'][$itemId]['level']; } } //link bakken $html .=""; //naam weergeven, bij parent bold maken if ($menuData['items'][$itemId]['parent_id'] == "0") { $html .=""; } //echo naam $html .="".stripslashes($menuData['items'][$itemId]['page_naam']).""; //$html .="($last_parent)"; //bold-tag afsluiten voor hoofditems if ($menuData['items'][$itemId]['parent_id'] == "0") { $html .=""; } //link afsluiten $html .=""; // find childitems recursively $html .= buildMenu($itemId, $menuData); $html .= '
  • '; } $html .= '
'; } return $html; } // output the sitemap echo buildMenu(0, $menuData); ?>