Are those pages sorted by some particular order?
Because if it’s just a normal order you can use a simple filterBy I think. So something like this maybe?
It takes the current page and get the 5 next items. If it’s at the end of the collection it will start over again. As long as the initial filtered collection is above 5 items it will always return 5 items.
Why?
I use it kind of as a gallery of related pages. What I think is nice with it is that every page have a unique set of related pages.
Is this for a blog or something? Where you give the user some related content at the end of the page?
Because if that’s the case, why not just display 5 items at random?
I’m not too fond of random stuff, in general. If the visitor comes back to the page to look for that related product and it’s random, it can be gone. With 3000 pages it could take a few F5 presses to get it back.
Also it’s not nice for an SEO point of view. For Google it can look like the content changes all the time and I don’t think it’s a good way to keep the pages flow the pagerank.
Therefor I like to keep things as “stable” as possible.
Fair point.
I was suggesting the random approach because when you say…
What I think is nice with it is that every page have a unique set of related pages.
…that’s not exactly true.
Suppose you have 10 pages.
If I’m looking at page number 3 you then show me pages 4 to 8.
If I then open page 4 you show me pages 5 to 9 and that means that 80% of the suggestions are identical to the one displayed in the previous page.
If it’s possible to improve the code even more it would be nice. If it’s not possible, it’s fine anyway. It’s working great and that’s the most important thing.