我试图根据具有特定变量的条目数量在表达式引擎中读取单数或复数的单词,但没有任何运气。这是目前的情况:
exp:channel:entries channel="specialist" dynamic="no" search:sp_specialty="={segment_2}" }
{if total_entries <= 1 }
OUR SPECIALIST
{if:else}
OUR SPECIALISTS
{/if}
{/exp:channel:entries}
我可以使用段值匹配搜索吗?现在它不起作用。更简单的方法吗?
最佳答案
试试这个:
{exp:channel:entries
channel="specialist"
dynamic="no"
search:sp_specialty="={segment_2}"
}
{if count == '1'}
{if total_results == '1'}
OUR SPECIALIST
{if:else}
OUR SPECIALISTS
{/if}
{/if}
{/exp:channel:entries}
- 您想使用
total_results
而不是total_entries
。 - 检查 1 个或更少的结果是多余的,因为如果没有结果, channel 条目标签将不输出任何内容(除非您使用
{if no_results}
标签对)。
关于search - 我可以使用 ExpressionEngine 中的段来过滤搜索结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13124163/