SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple IF Statement To Call Class

    Hi, i have just finished coding a design into html / css. I have spit the code up into php includes for the HEADER, NAVIGATION and the FOOTER

    I have coded my navigation so that when a tab (page) is selected from navigation it has a different style. I have declared this style in the css called .selected

    Can someone help me write a simple IF statement, that will work like this:

    IF the current page is 'contact.php' echo '.selected' ELSE do nothing

    I was hoping to past this IF statement into the code for each tab / button so it would use the .selected class if it was on that page, thanks in advance for your help...

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    If the ELSE is doing nothing, you don't need to include the ELSE portion.

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Try this:

    PHP Code:

    <html>
    <body>

    <?php 
      
    switch( $_SERVER['REQUEST_URI'] )
      {
        case 
    '/about.html'    $selected 'ff0';     break;
        case 
    '/blog.html'    $selected '0ff';     break;
        case 
    '/contact.html'    $selected 'f0f';     break;
        case 
    '/terms.html'    $selected 'f00'; break;
        case 
    '/subscribe.html'    $selected '090'; break;
        default                         : 
    $selected '000';
      }
      
    $selected 'style="background-color:#' .$selected .'"';
    ?>

      <div <?php echo isset($selected) ? $selected NULL;?> >
       ...
       ...
      </div>

    </body>
    </html>

    Beware: All Apache Versions are not the same. If on the off-chance $_SERVER['REQUEST_URI'] does not return the value expected then try this script:

    PHP Code:
      echo '<pre>';
        
    print_r$_SERVER );
      echo 
    '</pre>';
      die; 
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  4. #4
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, thanks all for your help...


Bookmarks

Posting Permissions

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