How to deal with archive pages of blog posts in Sanity
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
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?