Menu Source Code
Part of the main site xml file: menu.xml
<?php
function displayMenu($menuId, $pageId)
{
// Loops through menu.xml file and calls sub function to display in context
// Add menu title
echo "<h1 style=\"text-align: center;\">Site Menu</h1>";
// Read the xml into simplexml file
$xml = simplexml_load_file("../siteStuff/menu.xml");
// Loop through elements
foreach($xml->menuItem as $item)
{
// Look for menu item from main subject headings
if($item->attributes() == $menuId)
{
// Call for highlighted menu item
displayMenuItem("highlighted", $item->title->a->attributes(),
$item->title->a, 1);
// Now search all sub items
$subXml = $item;
// Loop through the sub items
foreach($subXml->menuItem as $subItem)
{
// Look for individual page and highlight if found
if($subItem->attributes() == $pageId)
{
displayMenuItem("selected", $subItem->title->a->attributes(),
$subItem->title->a, 3);
}
else
{
displayMenuItem("subMenu", $subItem->title->a->attributes(),
$subItem->title->a, 0);
}
}
}
else
{
displayMenuItem("highlighted", $item->title->a->attributes(),
$item->title->a, 2);
}
}
}
function displayMenuItem($class, $link, $text, $sub)
{
// Displays the menu item with or without highlight icon
if($sub == 2)
{
echo "<span class=\"$class\"><a href=\"$link\">" .
"$text <img src=\"../menu/right.png\" alt=\"arrow\" /></a></span>";
}
else if ($sub == 1)
{
echo "<span class=\"$class\"><a href=\"$link\">" .
"$text <img src=\"../menu/down.png\" alt=\"arrow\" /></a></span>";
}
else if ($sub == 3)
{
echo "<span class=\"$class\"><a href=\"$link\">" .
"$text <img src=\"../menu/left.png\" alt=\"arrow\" /></a></span>";
}
else
{
echo "<span class=\"$class\"><a href=\"$link\">$text</a></span>";
}
}
// Capture menu item from page that was posted
$posted = urldecode ( implode ( file ('php://input')));
list($menuId, $pageId) = explode(";", $posted, 2);
// Call display function
displayMenu($menuId, $pageId);
?>


