← Back to index

5.5 Sanity GROQ Queries (Content Fetching)

Heydays · static query examples (run in Next.js + next-sanity)

Projects listing

Ordered by Sanity’s orderRank; expands thumbnail asset, crop, and categories.

*[_type == "project"] | order(orderRank asc) {
  _id,
  title,
  slug,
  tagline,
  thumbnail {
    asset->{url, metadata{dimensions}},
    crop,
    hotspot
  },
  categories[]->{ title },
  layoutHint
}

Single project by slug

Portable Text fields omitted here; includes prev/next project references for case-study navigation.

*[_type == "project" && slug.current == $slug][0] {
  _id,
  title,
  tagline,
  description,
  deliverables,
  clientUrl,
  images[] {
    asset->{url, metadata{dimensions}},
    crop,
    hotspot,
    alt,
    caption
  },
  previousProject->{ title, slug },
  nextProject->{ title, slug }
}

Next.js usage

client.fetch(projectsQuery) in generateStaticParams / server components; params feed $slug for detail routes.

This repo has no Sanity client — copy queries into your app’s lib/queries.js.