我需要在条目模板中多次输出一个条目的类别。
因此,我想要获取以下内容的输出并将其分配给一个变量,以便我可以在模板中重复使用:
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}{category_name}{/categories}
{/exp:channel:entries}"
如何做到这一点?
我需要在条目模板中多次输出一个条目的类别。
因此,我想要获取以下内容的输出并将其分配给一个变量,以便我可以在模板中重复使用:
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}{category_name}{/categories}
{/exp:channel:entries}"
如何做到这一点?
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}
<?php $category = '{category_name}'; ?>
{/categories}
{/exp:channel:entries}
然后你可以在php变量"category"中存储{category_name}
。稍后您可以按照您的意愿重复使用它,例如将其打印:
<?php echo $category; ?>
您甚至可以将其与其他 EE 标签进行比较:
{exp:channel:entries channel="product" limit="1" status="open"}
{if <?php $echo($category) ?> == title}
This title have got the same value as the category!
{/if}
{/exp:channel:entries}
Croxton的Stash:http://devot-ee.com/add-ons/stash几乎可以做到Derek(上面提到的)所做的NSM Transplant一样,并且是免费的。其中任何一个附加组件都肯定是实现您尝试完成的任务最简单的方法。
EE没有内置的方法来保存标签循环中的数据并在模板之外的其他地方重复使用它。
一种解决方案是使用NSM Transplant来实现您要做的事情。
另一种方法是将整个条目页面包装在channel:entries
标记中,这样您就可以在需要的任何地方使用categories
循环,然后对于无法嵌套在channel:entries
中的任何内容,都可以使用嵌入。