Expression Engine Looping Category Entries
I have set-up a view template that displays a product and 3 next products (by entry_date) from that specific cate开发者_C百科gory. 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!
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.
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.
精彩评论