Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with menu

    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

    http://img256.imageshack.us/img256/1984/phpfoutvo6.jpg

    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.

    main-categorie:
    Code:
    	//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:
    Code:
    			<table class="sideMenu" border="0" cellpadding="0" cellspacing="0">
    <!-- BEGIN MENU -->
    				<tr>
    					<td>
    						<a class="menuItemInActiveNoSubs" href="{MENUITEMURL}">{MENUNAME}</a>
    <!-- BEGIN SUBMENU -->
    						<a class="menuItemInActiveNoSubs" href="{SUBMENUITEMURL}">&nbsp;&nbsp;&nbsp;{SUBMENUNAME}</a>
    <!-- END SUBMENU -->
    					</td>
    				</tr>
    <!-- END MENU -->
    			</table>
    arrays are filled from the map-structure:
    Code:
    	//opvullen van de array met categoriŽn
    	$map = "files/menu/";
    	if ($handle = opendir($map)) {
    		while (false != ($file = readdir($handle))) {
    			   if ($file != "." && $file != "..") {
    					$menuItems[] = $file;
    			   }
    		}
    		closedir($handle);
    	}
    
    	//Array met subcategoriŽn opvullen
    	$subMap = "files/menu/".$_GET['menu'];
    	if ($subHandle = opendir($subMap)) {
    		while (false != ($subFile = readdir($subHandle))) {
    			   if ($subFile != "." && $subFile != "..") {
    					$subMenuItems[] = $subFile;
    			   }
    		}	
    		closedir($subHandle);
    	}

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    What's your question?

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why the sub-categories are shown under both the main-categories and how to solve it?

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    Code:
    <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'
    		}
    	}
    }
    </script>
    <style type="text/css">
    .hidden {
    	display: none;
    }
    .show {
    	display: block;
    }
    </style>

    This would be the menu
    Code:
    <a href="javascript:menu(1);" style="display:block;height:20px;width:100px;" class="sel">CATEGORY</a>
    <ul id="1" class="hidden">
    <li>subcategory1</li>
    <li>subcategory2</li>
    <li>subcategory3</li>
    </ul>
    <a href="javascript:menu(2);" style="display:block;height:20px;width:100px;" class="sel">CATEGORY</a>
    <ul id="2" class="hidden">
    <li>subcategory1</li>
    <li>subcategory2</li>
    <li>subcategory3</li>
    </ul>

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •