Hello all, long time no code but I'm back now.
There has to be a better way ( either using a function or switch statement ) to code the below:
//Example CSS
.menu_1{text-decoration:none;}
.menu_2{text-decoration:underline;}
//Example Home Page
$title = "Home";
if ($title = "Home") { $home = "menu_1"; } else { $home = "menu_2"; }
if ($title = "About") { $about = "menu_1"; } else { $about = "menu_2"; }
echo 'This is my home page.<br />'.
'<a href="home.php" class="'.$home.'">home</a> - <a href="about.php" class="'.$about.'">about</a>';
What I'm basically trying to accomplish:
if I'm currently on the home page then there is no text decoration for the link 'home'
- but there is an underline text-decoration for the about link
if I'm currently on the about page then there is no text decoration for the link 'about'
- but there is an underline text-decoration for the home link
Again, there has to be a better way ( perhaps using a function or switch statement ) that escapes me at the moment. Any help is much appreciated!
[EDIT 1]
Okay, so I just tested the above code and it doesn't really work as it can't assign menu_2 to the about link when on the home page.
Heres a graphical represtionation of what I would like to achieve:
On the home page:
Home - About - Contact
On the About Page:
Home - About - Contact
On the Contact Page:
Home - About - Contact
All where:
.menu_1{text-decoration:none;}
.menu_2{text-decoration:underline;}
[EDIT 2]
Okay this works, but again, there must be a better way to code this!
//pre-define menu styles
$home = 'menu_2';
$about = 'menu_2';
$contact = 'menu_2';
//re-define menu styles
switch ($title)
{
case 'Home':
$home = 'menu_1';
break;
case 'About':
$about = 'menu_1';
break;
case 'Contact':
$contact = 'menu_1';
break;
default:
break;
}
echo 'This is my home page.<br />'.
'<a href="home.php" class="'.$home.'">home</a> - <a href="about.php" class="'.$about.'">about</a> - <a href="contact.php" class="'.$contact.'">contact</a>';