表达式引擎:将条目分组
简单问题:如何将给定通道中的所有条目输出到 4 个组中,如下所示:
<div class="entry_group">
<div class="entry" id="1"><span>{title}</span></div>
<div class="entry" id="2"><span>{title}</span></div>
<div class="entry" id="3"><span>{title}</span></div>
<div class="entry" id="4"><span>{title}</span></div>
</div>
<div class="entry_group">
<div class="entry" id="5"><span>{title}</span></div>
<div class="entry" id="6"><span>{title}</span></div>
<div class="entry" id="7"><span>{title}</span></div>
<div class="entry" id="8"><span>{title}</span></div>
</div>
提前致谢!
Quick question: How can I output all entries from a given channel into groups of 4, like so:
<div class="entry_group">
<div class="entry" id="1"><span>{title}</span></div>
<div class="entry" id="2"><span>{title}</span></div>
<div class="entry" id="3"><span>{title}</span></div>
<div class="entry" id="4"><span>{title}</span></div>
</div>
<div class="entry_group">
<div class="entry" id="5"><span>{title}</span></div>
<div class="entry" id="6"><span>{title}</span></div>
<div class="entry" id="7"><span>{title}</span></div>
<div class="entry" id="8"><span>{title}</span></div>
</div>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用 Modulo Operator 插件 通过任意数量的条目来实现此目的。类似这样:
该插件仅适用于 EE1,但将插件从 EE1 转换为 EE2 是轻而易举的事。
You can try using the Modulo Operator plugin to acheive this with any number of entries. Something like this:
The plugin is for EE1 only, but converting a plugin from EE1 to EE2 is a breeze.
我在 ExpressionEngine 论坛上找到了另一个更简单的解决方案;虽然相当基本,但我认为它应该相当容易地实现预期目标: http://expressionengine.com/ forums/viewthread/197240/#927740
其要点涉及使用 {switch} 变量来选择性地在每 n 组条目之后插入结束和开始标记对,具体取决于有多少个条目您在开关中留下的空白点。在您的情况下,示例将是这样的:
div
和class=entry_group
之间的空白不应导致任何问题,但如果确实如此,您可能需要使用 CSS 控制容器的属性,而无需在其上放置类(例如.entry_list>div{...
和.entry_list>div .entry{...
代码>I found another, much simpler solution on the ExpressionEngine forums; while fairly basic I think it should accomplish the desired goal fairly easily: http://expressionengine.com/forums/viewthread/197240/#927740
The jist of it involves using the {switch} variable to optionally insert closing and opening tag pairs after every n group of entries, depending on how many blank spots you leave in the switch. In your case, the example would be something like this:
The whitespace between the
div
andclass=entry_group
shouldn't cause any issues, but if it does you may want to use CSS to control the properties of the containers without having to put a class on them (e.g..entry_list>div{...
and.entry_list>div .entry{...
我确实在表达式引擎论坛上找到了半解决方案,但它需要对条目总数。
I did find a semi-solution on the Expression Engine forums, but it requires a limit on the total number of entries.