Active navigation pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oodya
Forum Newbie
Posts: 5
Joined: Sun Jun 14, 2009 7:45 am

Active navigation pages

Post by oodya »

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,
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Active navigation pages

Post by McInfo »

When you post code in the forums, remember to use BBCode tags.

Code: Select all

[code=php]
or [/code]
I am having difficulty visualizing how your pages are related to each other. Are all of the files in the same directory? Would you be able to post all of the pages (include only the relevant HTML, PHP, and CSS)?

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:53 pm, edited 1 time in total.
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: Active navigation pages

Post by paqman »

First step would be to link the CSS file to your page...

Code: Select all

<link type="text/css" rel="stylesheet" href="style.css">
Post Reply