Jump to content

Active navigation pages


oodya

Recommended Posts

Hi,

 

Currently what I am trying to do, is on my website, if someone is on a certain page, the button for that changes to a different colour (e.g. if someone clicks on "About Us", then when they go into the page, the rest of the buttons stay one colour and the About Us is a different colour.  I currently have the following pages on my site:

 

The CSS, a page called "pages.php" (which has all the navigation buttons on) and the actual site contents (contactus.php, aboutus.php, gallery.php) etc.  All the pages with the site contents have the include function, to include pages.php.  Before I had the pages.php file, I used a command like

 

<a href="#" class=" active"><span><span>Home</span></span></a> 

 

This meant that when the homepage.php was clicked on, the button would change colour (when the user enters the page).  Since creating the extra pages.php page, I am unable to do this.  I have been given some guidance to add something like the following to the pages.php:

 

  <ul class="artmenu">

 

                      <?

$x = "";

if ($_SERVER['SCRIPT_NAME'] == "categories.php") {

$x = "active";

}

?>

<li><a href="categories.php" class=" <? echo $x; ?>"><span><span>Gallery</span></span></a></li>

                    </ul>

 

But I am unable to get this to work.  The main reason for this is because I think there is no link from the pages.php file to the CSS.  Can someone assist please?

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/163934-active-navigation-pages/
Share on other sites

from PHP's help:

 

'SCRIPT_NAME'

Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

 

Which means than SCRIPT_NAME contains more than only file name (at least '/' + file name).

Try echoing it to see.

 

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.