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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.