•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 375,276 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,047 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
This is about as simple as it gets with menu generators. Everything is explained in the code. Note that the menu is simply an unordered list so to pretty it up it really relies on the CSS.
If you don't want to write any CSS of your own here is a sample stylesheet.
If you don't want to write any CSS of your own here is a sample stylesheet.
css Syntax (Toggle Plain Text)
#Menu { position:absolute; width:95%; height:44px; z-index:3; left: 4px; top: 175px; } .tabbedmenu { padding: 3px 0; margin-left: 0; font: bold 12px Verdana; border-bottom: 2px groove #F16C0A; list-style-type: none; text-align: left; } .tabbedmenu ul { margin: 0; padding: 0; float: left; } .tabbedmenu li { display: inline; position: relative; margin: 0; } .tabbedmenu li li{display: block;} .tabbed menu li li:hover{display: inline;} .tabbedmenu li a { text-decoration: none; padding: 3px 7px; margin-right: 3px; border: 3px double gray; border-bottom: none; background-color: #000000; color: #FFFFFF; } .tabbedmenu li a:hover { background-color: #F16C0A; color: black; } .tabbedmenu li a:active {color: #FFFFFF;} .tabbedmenu li a.selected { position: relative; top: 1px; padding-top: 4px; background-color: #F16C0A; color: white; }
Last edited : Sep 11th, 2007.
<?php /* * @brief print the menu to the page * @param string selected What is the current page? */ function writeMenu ($selected="index") { /* the only tedious part is that a boolean variable has to be made * for each new page and a case put in the switch */ $index = $staff = $contact = $links = false; $sel = 'class="selected"'; //change the class for selected page here switch($selected) { case 'staff': $staff = true; break; case 'links': $links = true; break; default: //fallthrough case 'index': $index = true; break; } // add pages in this array $pages = array("index", "staff", "links"); //Change the div ID and the list class here echo '<div id="Menu">'."\n\t".'<ul class="tabbedmenu">'; /* * This loop will generate a link on the menu. * Page name is automatically generated by the link. * IE: pages.php will show up as Pages on the menu * (can be overridden as shown below by explicitly * setting the value). */ for($i=0;$i<count($pages);$i++) { $html = "\n\t\t".'<li><a href="'.$pages[$i].'.php" '; $html .= ($$pages[$i]==true)?$sel:""; $pages[0]= "home"; //pagename override $html .='>'.ucfirst($pages[$i]).'</a></li>'; echo $html; } $html .= '</ul>'."\n".'</div>'."\n"; echo $html; } ?>
Comments (Newest First)
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)