Forum Moderators: coopster

Message Too Old, No Replies

Usability - Current folder highlighting

usability current page highlighting

         

Nealreal

5:17 pm on Mar 3, 2009 (gmt 0)

10+ Year Member



Usability is important to me. Showing visitors where they are by highlighting the link (using CSS) in the menu of the page they are currently on allows the site to be more usable. This is the following code I found that works well, if the person is on the "about.php" page:

<?
$path = $_SERVER['PHP_SELF'];
$page = basename($path);
$page = basename($path, '.php');
?>

<ul id="nav">
<li><a href="about.php" <? if($page == 'about') print ' class="current"'; ?></a></li>
</ul>

The IF statement prints a 'class="current"' into the link allowing the CSS to display my style for a current page - in turn, highlighting.

My problem is I need a new code. My website has sections now (folders), these sections make up the top navigation of my site (these are links to inside each folder). These sections are: About, Services, Work, Articles. I've organized my file structure the same, so I have 4 different folders labeled: About, Services, Work, Articles.

Each folder contains the PHP files for that section. Example:

Folder "about"
* company.php
* services.php
* history.php

The files links would look like this:
* about/company.php
* about/services.php
* about/history.php

Now, remember the top navigation, these are all links to different sections / folders. Is it possible to have these links stay highlighted depending on the folder I'm in? For instance: "about/company.php" <--- this link would be highlighted using the codes above, but the top navigation link would also be highlighted indicating that user was in the "about section".

What is the code for this?

[edited by: Nealreal at 5:19 pm (utc) on Mar. 3, 2009]

whoisgregg

9:42 pm on Mar 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you explode the $_SERVER['REQUEST_URI'] value on the slashes "/" then you should be able to use the output to determine what section they are in. :)

Nealreal

2:42 pm on Mar 4, 2009 (gmt 0)

10+ Year Member



I'm new to PHP so I would you to write out the complete code for me. THanks.

whoisgregg

3:18 pm on Mar 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wish that I had the time to write out complete code for people, but I have a full time job and simply volunteer my time here.

If you attempt to write the code and have trouble, post what you've tried so far and how it isn't working, and I know you will get help from myself or from the many helpful WebmasterWorld members who frequent this forum.

Nealreal

6:51 pm on Mar 8, 2009 (gmt 0)

10+ Year Member



Thanks for your help. I found a solution

[edited by: coopster at 9:45 pm (utc) on Mar. 8, 2009]
[edit reason] removed link to non-authoritative site [/edit]