How can I make a nice menu with multiple tiers
Moderator: General Moderators
How can I make a nice menu with multiple tiers
I want to make a nice menu. I basically want to have a main menu, and a sub menu that will span the width of a page. For example I will have a main menu with things like project, task, contact,.... and when I click on project I want it to show the correct submenu of items associated with it. I am pretty sure I understand what I need to do to make the menu and submenu, the problem is that the only way I know how to do it is to include the code on every different page, having a file for every selection of the main menu and one for main menu. I would perfer to be able to have everything in one file. The naming convention are something like http://www.url.com/modules/name of what I need/other stuff Is there a way to look at the url using possibly one of the url functions to get the information that I need from it, so I can do a if statement to make everything in one file instead of multiples.
- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
What do you mean by populate? Do you mean how do I plan on making the different links in it? If so I would just hardcode those in. Right now the plan would be have a submenu file that has the submenu with links, then I would display that on the pages. But I would like everything to be in one file, and have an if statement to choose which submenu to display.
Maybe something like
Now for what you want to do with the URLs, you'll have to look at htaccess mod_rewrite or do something with one of the $_SERVER superglobals but I would have to look that up myself 
Code: Select all
<?php
// homepage.php
$thispage = 'home';
include ('menu.php');
// rest of page here ...
//about.php
$thispage = 'about';
include ('menu.php');
// rest of page here ...
// menu.php:
if ( $thispage === 'home') {
echo '<ul><li>This is the html for submenu home<li></ul>';
}
elseif ( $thispage === 'about') {
echo '<ul><li>This is the html for submenu about<li></ul>';
}
else {
echo '<ul>defaultmenu</ul>';
}- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
I think I understand what you mean. I have constructed menu systems that react to the query string in the address bar in the past - and I think that's what you're getting at.
Something akin to this will do you... let's assume that you have two menus; one for regular (default) use and one for members. This is the simplest form of what you are interested in:
However, I strongly recommend checking the content of the variables once you have them - particularly if you are using th "GET" method to pass usernames between pages, since this is a potential security risk.
Hope this is useful to you!
Something akin to this will do you... let's assume that you have two menus; one for regular (default) use and one for members. This is the simplest form of what you are interested in:
Code: Select all
$pagename = $_GET['pagename']; // Get the value of $pagename from the query string
$logged = $_GET['logged']; // As above for $status
if($pagename=="home" && $logged =="no" ){
include "path/to/default/menu.php";
}
if($pagename=="home" && $logged == "yes"){
if(isset($_SESSION['username']){
include "path/to/members'/menu.php";
}
else{
include "path/to/default/menu.php";
}
}
else{
// Whatever else you want to do
}Hope this is useful to you!