1

I have a website that uses a "load more" button. The process for this button can be found here:

http://craftsnippets.com/articles/infinite-scrolling-and-lazy-loading-with-craft-cms

I made it pretty much verbatim (structure-wise with Element API) to that article, but I want to skip the first 6 entries because they are featured elsewhere on the site. So I tried to add .offset('6') to the for loop, and that did skip the first 6 entries. But when the "load more" button is clicked it would display the second 6 entries again (duplicates) then when you click the button again it properly continues down the list of entries.

So, how can I skip the first 6 entries in this scenario without having duplicates?

2

If you always want to skip the first 6 entries, you can modify the Element API endpoint to add 6 to the offset number in the query criteria:

$criteria = [
    'section' => $settings['section'], 
    'limit' =>  $settings['limit'],
    'offset' =>  ($settings['limit'] * Craft::$app->request->getParam('offset')) + 6,
    'order' => $settings['orderBy'],
];

That should mean you're always receiving results that are offset by the required amount for your request, plus the first 6 entries that you always want to skip.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.