Creating a Dynamic Menu. Please Help Fix It.

Discussion in 'PHP' started by monkeyclap, Jun 22, 2011.

  1. #1
    Hi guys,

    Been trying to use the follow for the navigation menu, which is in header.php.

    <li><a href="/" <?php if ($home==true) echo 'class="active"'?>><span>home</span></a></li>
    Code (markup):
    and then on the corresponding page (i.e. index.php in this case) I'm using:

    <?php $home="true"; include("header.php");?>
    Code (markup):
    I know it's not the best way of doing it as it's not working! By the way I am a newbie so please don't laugh!

    Thanks in advance.
     
    Last edited: Jun 22, 2011
    monkeyclap, Jun 22, 2011 IP
  2. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Why not just have a file called "header.php" and have everything for the navigation menu in that file, then on "index.php" just do:
    <?php if($home) include('header.php');?>
    PHP:
     
    Lam3r, Jun 22, 2011 IP
  3. bobbydeo

    bobbydeo Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to add the class in the span tag see the right tag below:

    <li><a href="/" <?php if ($home==true) echo '<span class="active">'?>>home</span></a></li>
     
    bobbydeo, Jun 22, 2011 IP