πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

How to deal with archive pages of blog posts in Sanity

11 replies
Last updated: Mar 30, 2023
How would I deal with archive pages of blog posts? I have a normal Post model.
I have a pageBuilder array of sections for all pages and shared settings, navigation etc.

But a blog overview page with a pageBuilder is not the solution.

Would I create a singleTon for the blog archive and if so, what goes in there to show all the existing posts?
Mar 30, 2023, 8:56 AM
This would be handled just in your frontend no?
You could have a model to maybe set the page title and any extra copy needed for the blog archive page, but no need to list out all the blog entries in model in Sanity also
Mar 30, 2023, 9:08 AM
So /pages/blog/index.tsx would have a unique query only to display all the archives. But what if I want to have a Hero section from the pageBuilder array but I want to display all the blog posts no matter what. How would I deal with that? That is basically my only issue now
Mar 30, 2023, 9:11 AM
yeah than add the Hero into the model so you can set that in Sanity.
You just need to add a query in nextjs that retrieves the blog posts also alongside the page content
Mar 30, 2023, 9:13 AM
So you would have a blogArchive model which has all the fields set that you want added to Sanity.
Then in Nextjs, you make your query to blogArchive type and also query blogPost type with the fields you need
Mar 30, 2023, 9:17 AM
https://blog.novacare.no/multiple-queries-in-sanity-with-one-request/ is a nice example of combining multiple queries into 1
Mar 30, 2023, 9:19 AM
Aahhhhh, I get it.Since I dont need the pageBuilder on the archive I only need to copy the Hero section with a title, image, text and query this data on the /blog/index.tsx together with a another query to display alll the posts right?
Mar 30, 2023, 9:20 AM
Unique model for the archive only which matches the design right?
Mar 30, 2023, 9:20 AM
Yup
Mar 30, 2023, 9:20 AM
Thank you User! Appreciate it
Mar 30, 2023, 9:20 AM
np!
Mar 30, 2023, 9:21 AM
Great article btw thanks this will help
Mar 30, 2023, 9:22 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?