Zend - The PHP Company




Menus & Navigation

Add Code


PHP Tabs  

Type: code fragment
Added by: mbourque
Entered: 24/01/2005
Last modified: 01/12/2004
Rating: * (3 votes)
Views: 13709
This little script will allow you to add tabs to the tops of your pages.


<?

import_request_variables
("G","");

$tabArray['Yahoo'] = "http://www.yahoo.com";
$tabArray['PHP'] = "http://www.abc.com";
$tabArray['Ask'] = "http://www.ask.com";

print_tab_interface($tabArray$activeTab );

function 
print_tab_interface$tabArray$activeTab="Yahoo" ) {

   
// Configurable tab interface written in PHP
   // Written by Michael P. Bourque
   // michael@mbourque.com
   // Please let me know if you use this.

   
$tab_table_width "100%";

   
$spacer "http://www.geocities.com/mbourque/scripts/graydot.gif";

   print 
"<style>";
   print 
".tabSelected";
   print 
"{";
   print 
"font-family:Arial,Veranda;";
   print 
"font-size:9pt;";
   print 
"padding-left:10px;";
   print 
"padding-right:10px;";
   print 
"padding-top:0px;";
   print 
"padding-bottom:0px;";
   print 
"background-color:#FFFFFF;";
   print 
"}";

   print 
".tabDefault";
   print 
"{";
   print 
"font-family:Arial,Veranda;";
   print 
"font-size:9pt;";
   print 
"padding-left:10px;";
   print 
"padding-right:10px;";
   print 
"padding-top:0px;";
   print 
"padding-bottom:0px;";
   print 
"background-color:#F5F5F5;";
   print 
"}";

   print 
"</style>";

   print 
"<table width="$tab_table_width" height="22" border="0" cellpadding="0" cellspacing="0">";
   print 
" <tr>";
   print 
"  <td rowspan="3" height="22" valign="bottom" width="12"><img src="$spacer" alt="" width="12" height="1"></td>";

   foreach ( 
$tabArray as $key => $tab ) {
      print 
"  <td rowspan="3" width="1" height="22"><img src="$spacer" alt="" height="22" width="1"></td>";
      print 
"  <td valign="top" height="1"><img src="$spacer" alt="" height="1" width="100%"></td>";
      print 
"  <td rowspan="3" width="1" height="22"><img src="$spacer" alt="" height="22" width="1"></td>";
      print 
"  <td rowspan="3" valign="bottom" width="5" height="22"><img src="$spacer" alt="" height="1" width="5" /></td>";
   }

   print 
" </tr>";
   print 
"  <tr>";

   foreach ( 
$tabArray as $key => $tab ) { // Print tabs

      
$class = ($key==$activeTab) ? "tabSelected" "tabDefault";
      
$link "<a href="$PHP_SELF?activeTab=$key">".$key."</a>";
      print 
"   <td height="20" nowrap align="center" class="$class">$link</td>";

   }

   print 
" </tr>";
   print 
"  <tr>";

   foreach ( 
$tabArray as $key => $tab ) {

       if ( 
$key == $activeTab ) {
         print 
"   <td height="1" bgcolor="#ffffff"></td>";
       
} else {
         print 
"   <td height="1" valign="bottom"><img width="100%" height="1" src="$spacer" alt=""></td>";
       }

   }

   print 
"   <td height="1" valign="bottom"><img width="100%" height="1" src="$spacer" alt=""></td>";
   print 
"  </tr>";
   print 
"</table>";

   include(
$tabArray[$activeTab]);
}


Usage Example




Rate This Script





Search



This Category All Categories