Author Topic: Active navigation pages  (Read 131 times)

0 Members and 1 Guest are viewing this topic.

Offline oodyaTopic starter

  • Irregular
    • View Profile
Active navigation pages
« on: June 27, 2009, 07:58:32 PM »
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,

Offline dzelenika

  • Enthusiast
    • View Profile
Re: Active navigation pages
« Reply #1 on: June 28, 2009, 07:55:17 AM »
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.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.