View Full Version : Problem with menu

11-15-2006, 09:36 PM
Hi all, I have been searching on this problem for a long time and didnt find a solution, lets hoep you guys can help me :D


As you can see the sub-categories are shown under the all main-categories, normally it may only be shown under the main-categorie wich is pressed.


//Hoofdmenu opbouwen
$tpl->set_block("producten_tp", "SUBMENU", "submenus");
$tpl->set_block("producten_tp", "MENU", "menus");
foreach ($menuItems as $menuItem) {
$urlMenu = $_SERVER['PHP_SELF']."?menu=".$menuItem;
$tpl->set_var("MENUITEMURL", $urlMenu);
$tpl->set_var("MENUNAME", strtoupper($menuItem));
$tpl->parse("menus", "MENU", true);

//submenu opbouwen
if (($_GET['menu'] == $menuItem) && ($_GET['menu'] != "")) {
foreach ($subMenuItems as $subMenuItem) {
$urlSubMenu = $_SERVER['PHP_SELF']."?menu=".$_GET['menu']."&submenu=".$subMenuItem;
$tpl->set_var("SUBMENUITEMURL", $urlSubMenu);
$tpl->set_var("SUBMENUNAME", strtoupper($subMenuItem));
$tpl->parse("submenus", "SUBMENU", true);

template file:

<table class="sideMenu" border="0" cellpadding="0" cellspacing="0">
<!-- BEGIN MENU -->
<a class="menuItemInActiveNoSubs" href="{MENUITEMURL}">{MENUNAME}</a>
<a class="menuItemInActiveNoSubs" href="{SUBMENUITEMURL}">&nbsp;&nbsp;&nbsp;{SUBMENUNAME}</a>
<!-- END SUBMENU -->
<!-- END MENU -->

arrays are filled from the map-structure:

//opvullen van de array met categoriŽn
$map = "files/menu/";
if ($handle = opendir($map)) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$menuItems[] = $file;

//Array met subcategoriŽn opvullen
$subMap = "files/menu/".$_GET['menu'];
if ($subHandle = opendir($subMap)) {
while (false != ($subFile = readdir($subHandle))) {
if ($subFile != "." && $subFile != "..") {
$subMenuItems[] = $subFile;

SeeIT Solutions
11-16-2006, 09:15 AM
What's your question?

11-16-2006, 11:11 AM
why the sub-categories are shown under both the main-categories and how to solve it?

SeeIT Solutions
11-16-2006, 12:00 PM
So you only want the sub categories to be shown when the main category is clicked?

That's a javascript problem, not a php one.

I use this

Put this in the <head> space of the page.

<script language="javascript">
function menu(element) {
var show = document.getElementById(element);
var img = document.getElementById('img'+element);
if (show) {
if (show.className == 'show') {
show.className = 'hidden';
img.src = 'img/close.gif'
} else {
show.className = 'show';
img.src = 'img/open.gif'
<style type="text/css">
.hidden {
display: none;
.show {
display: block;

This would be the menu

<a href="javascript:menu(1);" style="display:block;height:20px;width:100px;" class="sel">CATEGORY</a>
<ul id="1" class="hidden">
<a href="javascript:menu(2);" style="display:block;height:20px;width:100px;" class="sel">CATEGORY</a>
<ul id="2" class="hidden">

That's just taken from a page I use, it's pretty basic and you'll have to change it to fit your site, but the base is there.