Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2006, 12:01 PM   PM User | #1
jim2810
New to the CF scene

 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jim2810 is an unknown quantity at this point
Include navigation formatting help

My first go with PHP!

I have a simple hyperlink navigation panel which is accessed by various content pages via an PHP 'include' statement. I would like to highlight the navigation link of the corresponding page so it looks as though it's pressed down. Ideally, I'd like to do it using CSS.

Can anyone help.
p.s. I would suggest any help is in the form of an idiot's guide?

Thanks
jim2810 is offline   Reply With Quote
Old 01-09-2006, 02:13 PM   PM User | #2
Pennimus
Senior Coder

 
Join Date: Jul 2005
Location: UK
Posts: 1,051
Thanks: 6
Thanked 13 Times in 13 Posts
Pennimus is on a distinguished road
The way I do this is to get the current page name and then use it to determine which style is applied to the link (and, indeed, remove the anchor so there is no link to the current page).

PHP Code:
$url basename($_SERVER['PHP_SELF']); 
That assigns the current page name to the variable $url. Then for each link in your navigation, you can use an if/else statement to show the correct item. For a homepage link in an unordered list, this might look like this:

PHP Code:
if ($url == index.php) {
  echo 
'<li class="active">Home</li>';
} else {
  echo 
'<li><a href="index.php">Home</a></li>';

You're then free to style the item corresponding to the page your on however you want using CSS.

- Adam
Pennimus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:07 AM.


Advertisement
Log in to turn off these ads.