我正在使用ExpressionEngine 2.2.1,并试图根据类别显示页面的一部分。如果没有选择某个类别的条目,我想隐藏整个部分。例如,我有一个网站,列出了一项最终将有竞争对手参加的赛事的信息。我希望该页存在之前的竞争对手被选择,然后想添加到适当的类别,一旦他们已被选中。该部分将有一个标题,上面写着“竞争对手”。如果还没有分配到该类别的竞争对手,我不仅不希望它显示竞争对手的空间,而且还希望隐藏标题。如何创建基于类别的条件条件?以下是基于我的研究(http://expressionengine.com/archived_forums/viewthread/136676/#759900)的当前代码的适用部分,它不起作用:
{if “{categories show_group=“4”}{category_name}{/categories}” != “”}
{categories}
<h2>COMPETITORS</h2>
{exp:channel:entries channel="competitor_profiles_en" category_url_title="london_2d_en" orderby="date" limit="8" }
<div class="xx">{competitor_image}</div>
{/exp:channel:entries}
{/categories}
{if:else}
show nothing
{/if}发布于 2012-03-29 23:59:57
你就不能这么做吗?
{exp:channel:entries channel="competitor_profiles_en" category_url_title="london_2d_en" orderby="date" limit="8"}
{if count == "1"}<h2>COMPETITORS</h2>{/if}
<div class="xx">{competitor_image}</div>
{/exp:channel:entries}或者,如果您在循环遍历所有类别时执行此操作:
{exp:channel:categories channel="competitor_profiles_en" show_empty="no"}
<h1>{category_name}</h1>
{category_description}
<h2>COMPETITORS</h2>
{exp:channel:entries channel="competitor_profiles_en" category="{category_id}" orderby="date" limit="8"}
<div class="xx">{competitor_image}</div>
{/exp:channel:entries}
{/exp:channel:categories}请注意,如果您有许多类别,这种标记嵌套可能会导致相当大的性能损失。
发布于 2014-04-02 18:53:15
我通过将parse="inward"添加到channel:entries标记来实现这一点:
{exp:channel:entries channel="news" parse="inward"}然后是下面的if语句:
{if '{categories show="135"}{category_name}{/categories}' != ""}显然,请替换上面的频道和类别ID。所以完整的代码是:
{exp:channel:entries channel="news" parse="inward"}
{if '{categories show="135"}{category_name}{/categories}' != ""}
{!-- do something here --}
{/if}
{/exp:channel:entries}发布于 2012-03-29 19:57:44
这是完整的代码吗?
{categories}{/categories}循环对仅在通道:条目标记对中可用。
我并没有完全理解您想要做的事情,但是您可以在channel中使用一个条件:entries循环,如果没有基于使用标记的结果:
{if_no_results}。
在类别模式下加载模板时,这可能用于创建所需的视图,但没有分配给类别的条目。
https://stackoverflow.com/questions/9913282
复制相似问题