Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2012, 05:51 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
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
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 11-19-2012 at 10:22 AM..
LJackson is offline   Reply With Quote
Old 11-18-2012, 06:27 PM   PM User | #2
poyzn
Regular Coder

 
poyzn's Avatar
 
Join Date: Nov 2010
Posts: 265
Thanks: 2
Thanked 61 Times in 61 Posts
poyzn is on a distinguished road
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><?
...
}
__________________
Ushousebuilders.com
poyzn is offline   Reply With Quote
Users who have thanked poyzn for this post:
LJackson (11-18-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:08 PM.


Advertisement
Log in to turn off these ads.