Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts

    styling of navigation using php - advice needed

    Hello. I'm after some advice on the best way to do this.

    I use an include() for header.php on each page of my website, and I want to style the navigation so that page name is highlighted for whatever page the user is on (like this http://www.seanhurley.com

    As header.php is the same for each page it's included on I obviously can't just style them individually, but this is the idea I came up with.

    Place $page = 'homepage' , (or whatever page it is), before the including header.php. And then for the navigation having something like this:

    Code:
    <ul>
     <li <?php if($page=="homepage") { echo "class='highlight'"; }>homepage</li>
     <li <?php if($page=="about us") { echo "class='highlight'"; }>about us</li>
    </ul>
    I think this would work, but is there a better way of doing this as it seems a bit clumsy to me?

    Many thanks
    Patrick
    Last edited by paddyfields; 02-22-2013 at 04:52 PM.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    727
    Thanks
    20
    Thanked 85 Times in 85 Posts
    The link you gave is done in CSS

    you can get some good results with http://cssmenumaker.com/
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Thanks, but I don't mean all of the flashy drop down/hover malarky it has, just the highlighting of the current page. I've just tried what I wrote above and it does work, I'll probably just go with that. I just like to make sure there's not a cleaner way to do it.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    727
    Thanks
    20
    Thanked 85 Times in 85 Posts
    its fine like that or you can put the class in a variable too

    eg.

    PHP Code:
    <?php $page="homepage"$hi" class='highlight'";?> 
    <ul>
     <li<?php echo $page=="homepage" $hi:''?>>homepage</li>
     <li<?php echo $page=="about us" $hi:''?>>about us</li>
    </ul>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •