tspore Posted October 18, 2007 Share Posted October 18, 2007 Hey guys, I have created a php menu on my site. Basically all I have done, for each page is simply make a header.php, menu.php, and footer.php. For simplicity later to modify content. But I can't figure out how to get the page that I am on to show the active page in the menu. (You know I changed the css to remove the underline on that page, and be a different color. ) So right now on this page: http://fourthirdsphoto.com/special/e3links.php but the link is to that page is the same color as every other page. Quote Link to comment https://forums.phpfreaks.com/topic/73804-active-links-on-a-php-menu/ Share on other sites More sharing options...
~n[EO]n~ Posted October 18, 2007 Share Posted October 18, 2007 Ok, do like this :: You have included (menu.php) in other pages so, do like this suppose i have a page index.php there you keep one variable <?php $is_index_page = TRUE; ?> and then in menu.php file check if the variable is set, if it is set apply one css (with the color, hover whatever you want) else apply other style , same for other links too... <?php if(isset($is_index_page)) { ?> <td class="homepage_on_style">YOU ARE IN HOME PAGE</td> <?php } else { ?> <td class="homepage_off_style"><a href="index.php" class="classic">ACCUEIL</a></td> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73804-active-links-on-a-php-menu/#findComment-372423 Share on other sites More sharing options...
bronzemonkey Posted October 19, 2007 Share Posted October 19, 2007 In my header.php file I have this: <?php $page = $_SERVER['PHP_SELF']; $active = ' class="active"'; ?> And then my menu links are like this: <?php echo "<a"; if($page == '/index.php' ) { echo($active); } echo " href=\"/index.php\" title=\"Link title\">Home</a>\n"; ?> Just replace /index.php with the link to each page. There may well be better ways, I don't know much about php, but no one in the php forum provided me with anything better. Use it if it works for you...or until someone shows you something better. Quote Link to comment https://forums.phpfreaks.com/topic/73804-active-links-on-a-php-menu/#findComment-372845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.