You are here:  » IF statement for Categories

Support Forum



IF statement for Categories

Submitted by steve on Wed, 2008-09-24 12:54 in

Hi David,

Just a quick question for you.

In my header I have this html format for my top navigation

<li class="nav_mobile"><a href="/category/mobilephones/" class="nav_mobile ">Mobile Phones </a></li>

class="nav_mobile" is the unselected button and class="nav_mobile selected" shows my selected button.

So I was thinking of having an IF statement such as IF category equals mobilephones print selected.

I can then do this for all my buttons so the correct button will be displayed as being selected when browsing different products based on their category.

Could you tell me this in code?

Cheers! Steven :-)

Submitted by support on Thu, 2008-09-25 07:18

Hi Steven,

I always use PHP's shortand IF/THEN/ELSE construct for this kind of thing - it keeps everything nice and neat. For example:

<li class="nav_mobile"><a href="/category/mobilephones/" class="nav_mobile <?php print ($parts[0]=="category"&&$parts[1]=="mobilephones"?"SELECTED":""?>">Mobile Phones </a></li>

Cheers,
David.