Re: [PHP] tabbed navegation PHP
- From: lists@xxxxxxxxx (Jim Lucas)
- Date: Sat, 31 Mar 2007 01:36:26 -0700
Dwayne Heronimo wrote:
Dear All,
I have made a tabbed navegation with CSS. And if you set class="active" to one of the tabs, it will then be highlighted.
So I thought to make this dymamic with PHP. Using the $_GET variable I can get the page name above with something like. $page_name = $_GET['page'] ;
so I can tell the class when to be active to what page.
Should I use the isset function for this? I am very new to PHP but here is my try, but of course its not working:
<?php
if (isset ($_GET['page'])) {
$page_name = $_GET['page'] ;
if ($page_name = "default") {
$flg_page_default=1;
}
if ($page_name = "about") {
$flg_page_about=1;
}
}
?>
<a <?php if(!isset($flg_page_default)) echo 'class="active"'; else echo ''; ?> href="index.php?page=default"><span>home</span></a>
<a <?php if(!isset($flg_page_about)) echo 'class="active"'; else echo ''; ?> href="index.php?page=default"><span>about</span></a>
Of should I stick to just static html :(
Dwayne
Close, but this is probably how you should do it
$links = array();
url display
$links['default'] = "Home";
$links['about'] = "About";
etc...
foreach($links AS $url => $text) {
$class = '';
if ( isset($_GET['page']) && $_GET['page'] == $url ) {
$class = ' class="active"';
}
echo "<a href='index.php?page={$url}'{$class}><span>{$text}</span></a>\n";
}
This will allow you to change one piece of code, instead of twenty lines later on.
Use a little of the DRY principle.
Jim Lucas
.
- References:
- tabbed navegation PHP
- From: "Dwayne Heronimo"
- tabbed navegation PHP
- Prev by Date: Re: [PHP] FastCGI + PHP5
- Next by Date: Re: [PHP] Saving css state in javascript and passing to php via form submit
- Previous by thread: Re: [PHP] tabbed navegation PHP
- Next by thread: Re: [PHP] Show filenames using Wildcards -- The glob() Solution!
- Index(es):
Relevant Pages
|