This is a simple problem but i've been pulling my hair out the past two hours trying to figure a way to get it to work.
Basically I have a jquery navigation set-up. I have 4 tabs, each tab is a parent category with child categories. When a tab is clicked, a drop down with the children appears. I have it all set-up but can't figure a way to add a class of "active" to the child categories based on whatever category is selected.
Unless i've blanked and this is sitting right in front of my eyes, I can't find an obvious way of doing this. I think the problem is, I haven't hard coded the navigation links as the client want's to manage these themselves, so i've dynamically displayed the categories, adding an 'if' statement to this is adding the if statement to all of the categories so the class is being added to all of the child tabs.
Here is my code:
<div id="tabbed-cats">
{exp:channel:entries channel="product"}
<ul class="tabs">
<li class="nav-one"><a href="#bathroom" {categories}{if category_id == "1"}class="current"{/if}{/categories}>Bathroom</a></li>
<li class="nav-two"><a href="#homecare" {categories}{if category_id == "2"}class="current"{/if}{/categories}>Homecare</a></li>
<li class="nav-three"><a href="#transfer-equipment" {categories}{if category_id == "3"}class="current"{/if}{/categories}>Transfer Equipment</a></li>
<li class="nav-four last"><a href="#mobility" {categories}{if category_id == "4"}class="current"{/if}{/categories}>Mobility</a></li>
</ul>
{/exp:channel:entries}
<div class="list-wrap">
{exp:channel:entries channel="product"}
<ul id="bathroom" {categories}{if category_id == "2" OR category_id == "3" OR category_id == "4"}class="hide"{/if}{/categories}>
{exp:child_categories channel="product" parent="1" category_group="1" show_empty="yes"}
{child_category_start}
<li><a {categories}{if category_id == "5"}class="active"{/if}{/categories} href="{path='products/category/{child_category_url_title}'}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>
{/exp:channel:entries}
{exp:channel:entries channel="product"}
<ul id="homecare" {categories}{if category_id == "1" OR category_id == "3" OR category_id == "4"}class="hide"{/if}{/categories}>
{exp:child_categories channel="product" parent="2" category_group="1" show_empty="yes"}
{child_category_start}
<li><a {categories}{if category_id == "6"}class="active"{/if}{/categories} href="{path='products/category/{child_category_url_title}'}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>
{/exp:channel:entries}
{exp:channel:entries channel="product"}
<ul id="transfer-equipment" {categories}{if category_id == "1" OR category_id == "2" OR category_id == "4"}class="hide"{/if}{/categories}>
{exp:child_categories channel="product" parent="3" category_group="1" show_empty="yes"}
{child_category_start}
<li><a {categories}{if category_id == "8"}class="active"{/if}{/categories} href="{path='products/category/{child_category_url_title}'}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>
{/exp:channel:entries}
{exp:channel:entries channel="product"}
<ul id="mobility" {categories}{if category_id == "1" OR category_id == "2" OR category_id == "3"}class="hide"{/if}{/categories}>
{exp:child_categories channel="product" parent="4" category_group="1" show_empty="yes"}
{child_category_start}
<li><a {categories}{if category_id == "7"}class="active"{/if}{/categories} href="{path='products/category/{child_category_url_title}'}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>
{/exp:channel:entries}
</div><!-- END LIST WRAP -->
<br style="clear:both;" />