I have a navigation area that I am using include() to bring in some links so they show up on every page. I also want to have it so there is some type of marker on a link depending on what page you are on. How would I do this if all the links are being included from one source file but I want to apply CSS to a certain link?
Hi Copernicus, I'm not sure if I've got this right but you are including your navigation in a seperate file and you want to highlight a page if you're currently on it? Assuming I've got that right here's what I do: Firstly I have a template file for each individual link, it looks something like this: <a href="{$URL}"{$ACTIVE}>{$TITLE}</a> Code (markup): Then I pull my list of pages from the database, for simplicity's sake I'll use an array for this example: // Template string $nav_tpl = '<a href="{$URL}"{$ACTIVE}>{$TITLE}</a>'; // Template variable to output $navigation = ''; // Nav items $navitems = array(); $navitems[] = array( 'url' => 'index.php', 'title' => 'Homepage' ); $navitems[] = array( 'url' => 'about.php', 'title' => 'About Us' ); $navitems[] = array( 'url' => 'contact.php', 'title' => 'Contact Us' ); // Loop through the array, cache the template // into $navigation and replace the details foreach($navitems as $array) { // Cache the template $navigation .= $nav_tpl; // Replace variables $navigation = str_replace('{$URL}', $array['url'], $navigation); $navigation = str_replace('{$TITLE}', $array['title'], $navigation); // Give the navitem class="active" if we're on that page, // else remove {$ACTIVE} if(basename($_SERVER['PHP_SELF']) == $array['url']) { $navigation = str_replace('{$ACTIVE}', ' class="active"', $navigation); } else { $navigation = str_replace('{$ACTIVE}', '', $navigation); } } echo($navigation); PHP: Hopefully you can get what I'm trying to do here