I'm trying to create pagination on custom types, trying to set limitations but I see that it limits not exactly my articles, here I add screenshots of my custom type and the data structure that I get from prismic
I believe the "get all" methods like getAllByType do not return a paginated list where the standard methods do like getByType. See an example I use for my blog index: Documentation
I've included all but my structured data in case it helps:
import { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { SliceZone } from '@prismicio/react'
import * as prismic from '@prismicio/client'
import { createClient } from '@/prismicio'
import { components } from '@/slices'
import { Graph } from 'schema-dts'
import Section from '@/components/Section'
import BlogCard from '@/components/BlogCard'
import Pagination from '@/components/Pagination'
export default async function Page({
params,
searchParams,
}: {
params: Params
searchParams: SearchParams
}) {
const client = createClient()
const pageNumber = Number(searchParams['page']) || 1
const page = await client.getByUID('page', params.uid).catch(() => notFound())
let posts
if (page.uid === 'blog') {
posts = await client.getByType('post', {
orderings: {
field: 'document.first_publication_date',
direction: 'desc',
},
page: pageNumber,
pageSize: 5,
})
}
const settings = await client.getSingle('settings')
return (
<>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<SliceZone slices={page.data.slices} components={components} />
{/* CODE FOR BLOG PAGE ONLY */}
{page.uid === 'blog' && (
<Section width="md">
{posts && posts.results.length > 0 ? (
<ul className="px-4 lg:px-0">
{posts.results.map(post => {
return (
<BlogCard
key={post.id}
post={post}
className="mx-auto max-w-xl"
/>
)
})}
</ul>
) : (
<p className="prose mx-auto lg:prose-lg xl:prose-xl">
No posts have been published yet. Please check back again soon!
</p>
)}
{(posts?.next_page !== null || posts?.prev_page !== null) && (
<Pagination
hasNextPage={posts?.next_page !== null}
hasPrevPage={posts?.prev_page !== null}
totalPages={Number(posts?.total_pages)}
/>
)}
</Section>
)}
{/* END BLOG PAGE CODE */}
</>
)
}
Hello
Just thought of this, is there a way i can implement something like an infinite loading of more post on click of a button, 10 posts is going to be added to the list when you load more post