dynamic tabbed menus

Discussion in 'PHP' started by monkeyclap, Jun 7, 2010.

  1. #1
    hi there,

    just wondering how to make my nav menu (text only) highlight when i am on that specific page.

    i know that by using unique headers instead of a generic one will solve this issue, but that is just inefficient.

    can anyone help me? any help appreciated! thanks
     
    monkeyclap, Jun 7, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    So long as you know what page you are on when you generate the menu you can check to see if the page that the tab represents is the same as the current page and if so, you give that tab an additional class.

    
    
    $tabs = array('home'=>'Home', 'about'=>'About ABC Corp', 'contact' => 'contact us');
    
    foreach($tabs as $id => $label) {
       $cur = ($thisPage == $id)?'cur':'';
       echo "<li id='{$id}' class='{$cur}'>{$label}</li>";
    }
    PHP:
     
    sarahk, Jun 7, 2010 IP
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    how would i check to see if the page it's on is "right"? i guess i'll need to check the url?
     
    monkeyclap, Jun 8, 2010 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    that, or at the top of every page you set a variable eg $thisPage and then when you call header.php $thisPage already exists and is ready to check.
     
    sarahk, Jun 8, 2010 IP
    monkeyclap likes this.
  5. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #5
    thanks, got it :D
     
    monkeyclap, Jun 8, 2010 IP