Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •