Tutorials > Franciart.com Navigation TabsThe navigation might look like a lot of code since each tab has a different image (I am not following my own advice here, if you’ve read my suggestions for designing for the web), but in fact it’s actually very little code. All of my navigation links are in this array:
<?php
$navigation = array("index" => '/index.php', "about_me" => '/about_me.php', "art" => '/art.php', "tutorials" => '/tutorials/', "links" => '/links.php', "blog" => '/blog/', "contact" => '/contact.php'); ?> It’s good practice to keep your navigation links into an array (or variables) because pages get moved occasionally and this way, if I move something to a different folder or rename the page, I know that I only have to change the link in one place and all the other links across the site will change accordingly. I don’t use hardcoded links, for example I link to the tutorials page this way: <a href="<?php echo $navigation[‘tutorials’] ?>">tutorials</a>.
The images are named using the key in the array. I put the word "tab" in front of them, so that I know right away if I glance at the images folder, what that image is about. It’s good to be as descriptive as possible in naming things. So my standard is this: tab_key.jpg and tab_key_over.jpg, where key is "home", "about_me" etc... Now that I have this set up, all I have to do is cycle through the array to line the tabs out and to highlight the current one by checking if the key matches the $_SERVER['PHP_SELF'], which returns the current file.
<table cellpadding="0" cellspacing="0" id="navigation">
<tr> <?php if (preg_match('/'.$key.'/i', $_SERVER['PHP_SELF'])) { //highlight the tab of the current page echo '<td style="background: url(/images/tab_'.$key.'_over.jpg) 0 0 no-repeat;" class="link">'. str_replace('_', ' ', $key). </td>'; } else { echo '<td style="background: url(/images/tab_'.$key.'.jpg) 0 0 no-repeat;" class="link">'. '<a href="'.$value.'">'.str_replace('_', ' ', $key).'</a>'. '</td>'; } } ?> <td><img src="/images/end_piece.jpg" alt="" /></td> </tr> </table> |


