Hello iām trying to paginate a blog but still couldnāt find the way to do it with datocms. Iām fairly new to building websites. Iāve read the documentation https://www.datocms.com/docs/content-delivery-api/pagination and search tutorials on the internet but still havenāt found the best way to do it with datocms. If thereās anyone who can help me on this it will be much appreciated. Here is the website that iāve been working on https://www.wangsakerta.org/catatanlapangan. Thanks in advance
Hello @yayasan.wangsakerta and welcome to the community!
The best way to do it, is to pass the page index (that is, the number of the page) as a multiplier to the āskipā parameter.
Lets say you want to paginate your posts having 6 posts per page.
You would do the following request:
{
allPosts(first: 6, skip: 6 * index) {
id
author
}
}
This will make it so this request always return 6 records, and skips the firsts 6 * index records.
So if you are on the page with:
index = 1 you will get post 1- 6
index = 2 you will get posts 7-12
index = 3 you will get posts 13-18
And so on.