SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    Tucson, Arizona, USA
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating link navigation with if/else statements

    I'm working on a website that will have a left-hand navigation showing the major departments of the site. When a visitor clicks on a department link, it will show that link and a sub-menu of pages below it.

    In other words, they'd initially see:

    Department A
    Department B
    Department C

    Then, let's say they click on the Department A link. Then they'd see:

    Department A
    Page 1
    Page 2
    Page 3
    Department B
    Department C

    I'm told that this is done with HTML with if/else statements added to show the sub-menus.

    I haven't worked with if/else statements for a while, and was wondering if you'd mind refreshing my memory on how to implement them.

  2. #2
    SitePoint Evangelist Ed Seedhouse's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, B.C. Canada
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by azmartha View Post

    I'm told that this is done with HTML with if/else statements added to show the sub-menus.
    There isn't any such statement in HTML. HTML is a markup language, not a programming language.
    Ed Seedhouse

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    Tucson, Arizona, USA
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right, Ed. HTML certainly isn't a programming language. But you can put if/else statements inside of Server Side Include files. That's what I'm looking to do with this website's navigation.

  4. #4
    Design Your Site Team bronze trophy Erik J's Avatar
    Join Date
    May 2007
    Location
    Countryside, Sweden
    Posts
    3,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a working example of an expanding menu. View the source, its all there. (css+js)

    Found on this site. Look for expanding drop down.
    Happy ADD/ADHD with Asperger's

  5. #5
    SitePoint Evangelist Ed Seedhouse's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, B.C. Canada
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by azmartha View Post
    You're right, Ed. HTML certainly isn't a programming language. But you can put if/else statements inside of Server Side Include files. That's what I'm looking to do with this website's navigation.
    Server side includes are not html. They are a completely separate feature provided by the apache server software. I don't know if there is a SSI forum on sitepoint but if there is you should post your question there. Or possibly on an apache forum.
    Ed Seedhouse

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    Tucson, Arizona, USA
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Me again.

    I'm working on this problem, which seems like it would be best solved via PHP. Going the HTML/SSI route seems a bit too cumbersome. And the CSS/Javascript route may not be the best either. I've heard that JavaScript is not SE spider friendly. And you do want those spiders to have an effortless crawl through your site.

    With PHP, the code could "see" if the page is department-a.php or or department-b.php and show the sub-menu if yes. Otherwise, it won't show that particular sub-menu.

    I'll keep you posted...

  7. #7
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There isn't an SSI forum here on SitePoint, but there is a General Programming one. Also, SSI is not limited to Apache; it also works equally well on IIS.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    Tucson, Arizona, USA
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Me again.

    I'm back with some PHP code for link navigation using if/else statements. I've tested it on the site that I'm developing, and it works Firefox, MSIE, Opera, and Safari. The code also validates at the W3C.

    So, feel free to adapt the following for your own purposes...

    <ul>

    <?php if ($page == 'about') { ?>

    <li class="link-box"><a href="about.php"><strong>About Us</strong></a>
    <ul class="sub-menu">
    <li><a href="vision.php">Vision</a></li>
    <li><a href="team.php">Our Team</a></li>
    <li><a href="news.php">News</a></li>
    <li><a href="events.php">Events</a></li>
    </ul>
    </li>

    <?php } else { ?>

    <li class="link-box"><a href="about.php">About Us</a></li>

    <?php } ?>

    </ul>

    Feel free to expand your unordered list. I just kept this one brief so you can see what's going on with the if/else statements.

  9. #9
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    It looks like you've found your answer. If you have any other PHP related questions you might want to drop them in the PHP forum on SitePoint. I pretty much learned everything I know about PHP from the extremely friendly (and patient!) folks here on SitePoint.
    TAKE A WALK OUTSIDE YOUR MIND.


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
  •