0

これは単純な問題ですが、私はそれを機能させる方法を見つけようとして、過去 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;" />

4

2 に答える 2

1

EE 2.4 では、{if active}class="foobar"{/if}try that を使用して確認できるようになりました。

于 2012-04-20T16:15:15.923 に答える
0

URLのカテゴリURLタイトルに対して計算する必要があります。私はあなたが使用している子カテゴリプラグインに完全には精通していませんが、これはあなたの{exp:child_categories}ループ内で機能するはずです:

{if child_category_url_tile == segment_3} class="active"{/if}

同じチャネルエントリを5回呼び出してから、毎回条件付きカテゴリステートメントに基づいて表示内容をフィルタリングしているため、コードで何をしているのか完全にはわかりません。これが実際に完全なコードである場合は、再考とリファクタリングを真剣に検討する必要があります。ここでのあなたのオーバーヘッドは非常識です!

于 2012-04-20T03:42:57.770 に答える