Php ExpressionEngine类别-需要使用if语句添加动态类的帮助吗
这是一个简单的问题,但在过去的两个小时里,我一直在绞尽脑汁想办法让它发挥作用 基本上我有一个jquery导航设置。我有4个选项卡,每个选项卡都是带有子类别的父类别。单击选项卡时,将显示包含子项的下拉列表。我已经全部设置好了,但无法根据选择的类别,找到一种方法将“活动”类添加到子类别中 除非我已经盖好了毯子,而这个就在我眼前,否则我找不到一个明显的方法来做这件事。我认为问题在于,我没有硬编码导航链接,因为客户端希望自己管理这些链接,所以我动态显示了类别,向其中添加“if”语句就是将if语句添加到所有类别中,以便将类添加到所有子选项卡中 这是我的密码:Php ExpressionEngine类别-需要使用if语句添加动态类的帮助吗,php,if-statement,categories,expressionengine,Php,If Statement,Categories,Expressionengine,这是一个简单的问题,但在过去的两个小时里,我一直在绞尽脑汁想办法让它发挥作用 基本上我有一个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;" />
{exp:channel:entries channel=“product”}
{/exp:channel:entries}
{exp:channel:entries channel=“product”}
{exp:child\u categories channel=“product”parent=“1”category\u group=“1”show\u empty=“yes”}
{child_category_start}
{child_category_end}
{/exp:child_categories}
{/exp:channel:entries}
{exp:channel:entries channel=“product”}
{exp:child\u categories channel=“product”parent=“2”category\u group=“1”show\u empty=“yes”}
{child_category_start}
{child_category_end}
{/exp:child_categories}
{/exp:channel:entries}
{exp:channel:entries channel=“product”}
{exp:child\u categories channel=“product”parent=“3”category\u group=“1”show\u empty=“yes”}
{child_category_start}
{child_category_end}
{/exp:child_categories}
{/exp:channel:entries}
{exp:channel:entries channel=“product”}
{exp:child\u categories channel=“product”parent=“4”category\u group=“1”show\u empty=“yes”}
{child_category_start}
{child_category_end}
{/exp:child_categories}
{/exp:channel:entries}
您希望根据URL中的类别URL标题进行计算。我并不完全熟悉您正在使用的子类别插件,但它似乎应该在您的
{exp:Child_Categories}
循环中工作:
{if child\u category\u url\u tile==segment\u 3}class=“active”{/if}
我不完全理解您在代码中做了什么,因为您要调用相同的通道条目循环5次,然后根据条件类别语句过滤每次显示的内容。如果这实际上是您的完整代码,您应该认真考虑重新思考和重构。你的头顶太疯狂了 在EE 2.4中,您现在可以使用
{if active}class=“foobar”{/if}
试试看。只是想澄清一下-您希望在下拉列表中添加一个“active”类,该类链接到当前类别(即当前URL表示的类别)?@DerekHogue Hi Derek,是的,我需要向它添加一个活动类。不幸的是,这是将它与我的jquery脚本集成在一起的唯一方法。。。谢谢你,我会尝试一下。我在发布这篇文章的同时也修改了我的代码,这只是为了测试的目的。不管怎样,我总是事后检查代码并将其清理干净。