Log In · Register

 
current page style...?
Maccabee
post Jul 20 2009, 09:37 AM
Post #1


Senior Member
*******

Group: Official Designer
Posts: 5,880
Joined: Nov 2007
Member No: 593,382



I have seen on some sites, when you click on a nav link when you go the page, that link stays, highlighted or something signifying that you are still on that page. How do you do that? I thought you just used "a:active"? But im trying it out and it isnt working.
 
 
Start new topic
Replies
fixtatik
post Jul 20 2009, 10:14 PM
Post #2


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



You could use if statements and use CSS to style the "current" class:
CODE
<ul>
  <li><a<?php if($page == 'link-1') echo ' class="current"'; ?> href="#">Link 1</a></li>
  <li><a<?php if($page == 'link-2') echo ' class="current"'; ?> href="#">Link 2</a></li>
  <li><a<?php if($page == 'link-3') echo ' class="current"'; ?> href="#">Link 3</a></li>
</ul>

Of course, you'll just need to define what the variable $page is. If you have links like yoursite.com/link-1.php, you can get the file name and use that:
CODE
<?php
$page = $_SERVER['SCRIPT_FILENAME'];
$page = explode('.php', $page);
$page = $page[0];
?>

In this case, going to yoursite.com/link-1.php, $page is link-1.
 

Posts in this topic


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: