Simple IF Statement For Class

Discussion in 'PHP' started by oo7ml, Apr 3, 2012.

  1. #1
    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...
     
    oo7ml, Apr 3, 2012 IP
  2. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #2
    Bit of a hack script haven't tested - try it out to see if will do the job.

    
    <?php
    if(!empty($_SERVER['PHP_SELF'])) {
    echo '<link rel="stylesheet" type="text/css" href="'.getcwd().'/selected.css">';
    }
    ?>
    
    PHP:


    :)




    ROOFIS
     
    ROOFIS, Apr 3, 2012 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Cool, thanks for your help...
     
    oo7ml, Apr 4, 2012 IP
  4. Uploadables

    Uploadables Member

    Messages:
    100
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #4
    This is another option which you could use

    
    <a href="contact.php" <?php if([FONT=arial]$[/FONT][I]_SERVER[/I][FONT=arial]['[/FONT][I]PHP_SELF[/I][FONT=arial]'] [/FONT]== '/contact.php') echo "class='selected'";?>>Register</a>
    
    Code (markup):
     
    Uploadables, Apr 4, 2012 IP
  5. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    Cool, thanks...
     
    oo7ml, Apr 5, 2012 IP