Jump to content

Active Links on a PHP menu


tspore

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/73804-active-links-on-a-php-menu/
Share on other sites

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 
					 } 
					 ?>

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.