表达式引擎循环类别条目
我已经设置了一个视图模板,用于显示该特定类别中的一个产品和 3 个下一个产品(按 Entry_date)。我的问题是,我在一个类别中有 34 个产品,一旦我继续浏览下一个产品,我就会到达 34 个产品的末尾,并且它不会再显示。
如何让它循环回到第一个产品,即最新产品?
我并不是要求某人顺便给我代码,我只是需要一些关于使用什么代码的帮助,因为我搜索没有结果!
I have set-up a view template that displays a product and 3 next products (by entry_date) from that specific category. My problem is, I have 34 products in one category, once I keep going through the next products I hit the end of the 34 products and it won’t display anymore.
How can I make it loop back to the first product i.e. the latest product?
I'm not asking for someone to just give me the code by the way, I just need some assistance with what code to use as I've searched with no avail!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
循环实际上非常棘手,而且这种行为不是 EE 内置的。它将需要一些自定义编码。
我的第一个尝试是在支持 PHP 的模板或自定义插件中执行此操作,并获取类别中的所有条目,将它们放入一个数组中,并使用该数组作为创建“下一个”的基础。 3 个产品”链接。这样您就可以将当前产品与数组进行比较(可能使用entry_id作为键),并且如果数组中的剩余产品<= 3、通过从阵列前面拉出你需要的来进行补偿。
我知道,这是抽象的,但这应该是一个开始。
Looping is actually pretty tricky, and no, this behaviour is not built-in to EE. It will require some custom coding.
My first stab would be to do this either in a PHP-enabled template, or in a custom plugin, and grab all of the entries in the category, put them into an array, and use that array as the basis for creating your "next 3 products" links. That way you can compare the current product to the array (using maybe the entry_id as the keys), and if the remaining products in the array are < 3, compensate by pulling what you need from the front of the array.
Abstract, I know, but it should be a start.
这不就是分页吗?按正常方式对结果进行分页,限制为 3/4。
您可以使用内置 EE 条件检测何时没有更多结果(我一时想不起来)。
当您找到最后一个结果时,添加一个返回到第一个批次的链接。
您也可以使用 AJAX 来完成此操作,以获得更无缝的体验。
Isn't this just pagination? Paginate the results as normal limiting to 3/4.
You can detect when there are no more results using a built-in EE condition (can't recall off the top of my head).
When you hit the last results, add a link that goes back to the first lot.
You can probably do this with AJAX as well for a more seamless experience.