Thread: php tab select
View Single Post
Old 11-28-2011, 11:28 AM   #4 (permalink)
Parkinson4
The Visitor
 
Parkinson4's Avatar
 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Parkinson4 is on a distinguished road
Default

It's really not all that hard (at least compared to some things). There are a number of ways. One easy(?) way is to define a function that accepts an argument to indicate which one is selected:
PHP Code:
function tabs($active)
{
$tabs = array(
'Home' => '/index.php',
'About Us' => '/about/index.php',
'Contact Us' => '/contact/index.php'
);
echo "<ul id='tabs'>";
foreach($tabs as $label => $path)
{
if($label == $active)
{
echo "<li class='active'>$label</li>\n";
}
else
{
echo "<li><a href='$path'>$label</a></li>\n";
}
}
echo "</ul>\n";
}
Then in your pages:
PHP Code:
<html>...<body>
<?php
include $_SERVER['DOCUMENT_ROOT'].'/includes/functions.php';
tabs('Home');
?>
rest of page...
Parkinson4 is offline  
Reply With Quote