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 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation help with menu setting "current" tab when in a function

    Hi All

    i have a function which includes the header info for a site i am doing, im having trouble figuring out how to set a tab as "current" as this function is called on each page.

    the function is
    PHP Code:
    <?php function header_info()
    {
    ?>
        <!-- Header -->
        <header>
            <h1 class="logo"><a href="index.php"></a></h1>
            <nav>
                <ul class="sf-menu">
                    <li class="current"><a href="index.php">Home</a></li>
                    <li><a href="about.php">About</a></li>
                    <li><a href="services.php">Services</a></li>
                    <li>
                          <a href="portfolio.php">Portfolio</a>
                        <ul>
                               <li><a href="portfolio.php?gallery=hair">Hair Portfolio</a></li>
                               <li><a href="portfolio.php?gallery=beauty">Beauty Portfolio</a></li>
                               <li><a href="portfolio.php?gallery=wedding">Wedding Portfolio</a></li>
                               <li><a href="portfolio.php?gallery=tanning">Tanning Portfolio</a></li>
                               <li><a href="portfolio.php?gallery=training">Training Portfolio</a></li>
                               <li><a href="portfolio.php?gallery=miscellaneous">Miscellaneous Portfolio</a></li>                            
                        </ul>
                    </li>
                    <li><a href="promotions.php">Promotions</a></li>
                    <li><a href="contact.php">Contact</a></li>
                </ul>
            </nav>
            <div class="clear"></div>
        </header>
        
        <!-- Slider -->
        <div class="mp-slider">
            <ul class="items">
                <li><img src="images/slide-1.jpg" alt="" /><div class="banner"><span class="row-1"></span><span class="row-2"></span></div></li>

            </ul>
        </div><?php
    }
    as you can see the class of home is set to current but as this is within a function its always set to home no matter which page your on. how can i change the class "current" depending on the pae the user is on?

    many thanks
    Last edited by LJackson; 11-19-2012 at 10:22 AM.

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    pass a parameter to the function:
    PHP Code:
    <?
    function header_info($gallery) {
    ...
      
    ?><li><a href="portfolio.php?gallery=beauty" <? if($gallery == 'beauty') echo 'class="active"'?>>Beauty Portfolio</a></li><?
    ...
    }

  • Users who have thanked poyzn for this post:

    LJackson (11-18-2012)


  •  

    Posting Permissions

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