これは単純な問題ですが、私はそれを機能させる方法を見つけようとして、過去 2 時間髪を引っ張ってきました。
基本的に、私はjqueryナビゲーションをセットアップしています。4 つのタブがあり、各タブは子カテゴリを持つ親カテゴリです。タブをクリックすると、子のドロップダウンが表示されます。私はそれをすべてセットアップしましたが、選択されたカテゴリに基づいて子カテゴリに「アクティブ」のクラスを追加する方法を理解できません。
私が空白にしていて、これが私の目の前に座っていない限り、これを行う明白な方法を見つけることができません. 問題は、クライアントがこれらを自分で管理したいので、ナビゲーション リンクをハードコーディングしていないことだと思います。そのため、カテゴリを動的に表示しました。これに「if」ステートメントを追加すると、if ステートメントがすべてのクラスがすべての子タブに追加されるようにします。
これが私のコードです:
<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;" />