User Name Password Register
DaniWeb IT Discussion Community
All
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
Sep 11th, 2007
Views: 3,609
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.

  1. #Menu
  2. {
  3. position:absolute;
  4. width:95%;
  5. height:44px;
  6. z-index:3;
  7. left: 4px;
  8. top: 175px;
  9. } .tabbedmenu
  10. {
  11. padding: 3px 0;
  12. margin-left: 0;
  13. font: bold 12px Verdana;
  14. border-bottom: 2px groove #F16C0A;
  15. list-style-type: none;
  16. text-align: left;
  17. }
  18. .tabbedmenu ul
  19. {
  20. margin: 0;
  21. padding: 0;
  22. float: left;
  23. }
  24. .tabbedmenu li
  25. {
  26. display: inline;
  27. position: relative;
  28. margin: 0;
  29. }
  30. .tabbedmenu li li{display: block;}
  31. .tabbed menu li li:hover{display: inline;}
  32.  
  33. .tabbedmenu li a
  34. {
  35. text-decoration: none;
  36. padding: 3px 7px;
  37. margin-right: 3px;
  38. border: 3px double gray;
  39. border-bottom: none;
  40. background-color: #000000;
  41. color: #FFFFFF;
  42. }
  43. .tabbedmenu li a:hover
  44. {
  45. background-color: #F16C0A;
  46. color: black;
  47. }
  48. .tabbedmenu li a:active {color: #FFFFFF;}
  49. .tabbedmenu li a.selected
  50. {
  51. position: relative;
  52. top: 1px;
  53. padding-top: 4px;
  54. background-color: #F16C0A;
  55. color: white;
  56. }
Last edited : Sep 11th, 2007.
php Syntax
  1. <?php
  2. /*
  3.  * @brief print the menu to the page
  4.  * @param string selected What is the current page?
  5.  */
  6. function writeMenu ($selected="index")
  7. {
  8. /* the only tedious part is that a boolean variable has to be made
  9.   * for each new page and a case put in the switch */
  10. $index =
  11. $staff =
  12. $contact =
  13. $links = false;
  14. $sel = 'class="selected"'; //change the class for selected page here
  15. switch($selected)
  16. {
  17. case 'staff':
  18. $staff = true;
  19. break;
  20. case 'links':
  21. $links = true;
  22. break;
  23. default: //fallthrough
  24. case 'index':
  25. $index = true;
  26. break;
  27. }
  28. // add pages in this array
  29. $pages = array("index", "staff", "links");
  30.  
  31. //Change the div ID and the list class here
  32. echo '<div id="Menu">'."\n\t".'<ul class="tabbedmenu">';
  33.  
  34. /*
  35. * This loop will generate a link on the menu.
  36. * Page name is automatically generated by the link.
  37. * IE: pages.php will show up as Pages on the menu
  38. * (can be overridden as shown below by explicitly
  39. * setting the value).
  40. */
  41.  
  42. for($i=0;$i<count($pages);$i++)
  43. {
  44. $html = "\n\t\t".'<li><a href="'.$pages[$i].'.php" ';
  45. $html .= ($$pages[$i]==true)?$sel:"";
  46. $pages[0]= "home"; //pagename override
  47. $html .='>'.ucfirst($pages[$i]).'</a></li>';
  48. echo $html;
  49. }
  50. $html .= '</ul>'."\n".'</div>'."\n";
  51. echo $html;
  52. }
  53. ?>
Comments (Newest First)
emon | Newbie Poster | Mar 8th, 2008
sd sdf sdf sdf ds
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 6:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC