PHP include for menu

Discussion in 'PHP' started by buckmajor, Jan 23, 2011.

  1. #1
    Hi there

    I am trying to use PHP include for the menu. However, the menu navigation will have an extra class added each time a user links to that page.

    Example: Homepage
    <ul>
            <li><a href="home" title="Home" [B][COLOR="red"]class="home active"[/COLOR][/B]>Home</a></li>
            <li><a href="about" title="About" class="about'>About</a></li>
            <li><a href="contact" title="Contact" class="contact'>Contact</a></li>
    </ul>
    Code (markup):
    Does anyone know how to implement the PHP include for the menu if I need to change the class to a different page?

    Example: Contactpage
    <ul>
            <li><a href="home" title="Home" class="home">Home</a></li>
            <li><a href="about" title="About" class="about'>About</a></li>
            <li><a href="contact" title="Contact" [B][COLOR="red"]class="contact active"[/COLOR][/B]>Contact</a></li>
    </ul>
    Code (markup):
    Many thanks in advance
    CHEERS :)
     
    Last edited: Jan 23, 2011
    buckmajor, Jan 23, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    just before include, put this line

    or
    or
    depends on when you are and now include that menu. in that menu file, change that code to this

    hope it helps !
     
    G3n3s!s, Jan 23, 2011 IP
  3. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Excellent! Thank you very much G3n3s!s, it works. I got it working on my navigation and other areas of my website. I think I understand how var works now since I haven't used it before. This will be great for more heavier and complex website development.

    CHEERS :)
     
    buckmajor, Jan 23, 2011 IP
  4. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #4
    If you want more help, do not hesitate to create new topic/PM me! :)
     
    G3n3s!s, Jan 23, 2011 IP
  5. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Too easy, much appreciated. Oops, I didn't think it will be this soon :D. I had a little problem with my catcha on my contact page not sure why it didn't work??

    Example: Contactpage
    What do you reckon?
     
    buckmajor, Jan 23, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    I think you are missing

    $publickey = "#";
    $privatekey = "#";

    it should be different. You get key from recaptcha website I think
     
    G3n3s!s, Jan 23, 2011 IP
  7. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hello,

    Here is the PHP.

    
    
    <?php
    
        if($_SERVER['REQUEST_URI'] == "home"){
            $class_addon1 = " active";
        }
        
            else
            
        if($_SERVER['REQUEST_URI'] == "about"){
            $class_addon2 = " active";
        }
        
            else
            
        if($_SERVER['REQUEST_URI'] == "contact"){
            $class_addon3 = " active";
        }
    
    ?>
    
    
    PHP:
    Here is the HTML.

    
    
    <ul>
    
        <li><a href="home" title="Home" class="home<?=$class_addon1?>">Home</a></li>
        <li><a href="about" title="About" class="home<?=$class_addon2?>">About</a></li>
        <li><a href="contact" title="Contact" class="home<?=$class_addon3?>">Contact</a></li>
    
    </ul>
    
    
    HTML:
    I hope i helped.

    Thanks,

    Michael
     
    Last edited: Jan 23, 2011
    CPAPubMichael, Jan 23, 2011 IP
  8. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Thanks Mike

    G3n3s!s, I have a key but it is still not working
     
    buckmajor, Jan 24, 2011 IP
  9. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #9
    you're missing recaptchalib.php in folder/home/name/public_html/php/

    Mike, why are you replying when we already solved it yesterday?
     
    G3n3s!s, Jan 24, 2011 IP
  10. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #10
    Hey Gen,

    I have the file there but now this error message is showing:
    What do you reckon?
     
    buckmajor, Jan 24, 2011 IP
  11. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #11
    I just found out, PHP and HTML don't mix very well :(. I might have to find another way of getting this to work. Was doing some research and found Smarty template engine. If worse case, I might have to learn how to use Smarty and build all my sites from there if necessary.
     
    buckmajor, Jan 24, 2011 IP
  12. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #12
    I think there are a lot of free captcha classes with full explantation how to use them, just search ;)
     
    G3n3s!s, Jan 24, 2011 IP
  13. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I don't like to set here and read ALL the posts, just post my solution. Sorry if it was already solved.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 24, 2011 IP
  14. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #14
    FREEEDOOM!! I have finally got it working Gen, flip all that time I had the path wrong.

    Sweet, thanks again for your help Gen.
     
    buckmajor, Jan 24, 2011 IP
  15. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Haha, easily done. We all make mistakes and errors. Glad you got it working again.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 24, 2011 IP
  16. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #16
    It's okay ;)


    I am glad it's working ;)
     
    G3n3s!s, Jan 24, 2011 IP