To add featured posts in Astro, put featured: z.boolean().default(false) in your blog collection schema, set featured: true in the frontmatter of the posts you want to pin, and filter with getCollection('blog', ({ data }) => data.featured). Sort the result by date, limit it to a few posts, and fall back to the latest posts so the section is never empty.
Key Takeaways
- A featured post is a boolean in frontmatter, checked by the schema.
- Default it to
falseso you only edit the posts you pin.- Use a numeric
featuredOrderif you need a hand-picked order.- Fill empty slots with the newest posts so the layout stays complete.
- Exclude featured posts from the “latest” list below them to avoid duplicates.
Add the field
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
featured: z.boolean().default(false),
featuredOrder: z.number().int().optional(),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };
Pin a post:
---
title: "Our 2026 field guide"
description: "Everything we learned this year."
pubDate: 2026-10-01
featured: true
featuredOrder: 1
---
featuredOrder is optional. Without it, featured posts sort by date.
Write the helper
// src/lib/posts.ts
import { getCollection, type CollectionEntry } from 'astro:content';
type Post = CollectionEntry<'blog'>;
const byNewest = (a: Post, b: Post) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf();
export async function getPosts() {
return (await getCollection('blog', ({ data }) => !data.draft)).sort(byNewest);
}
export async function getFeatured(limit = 3) {
const posts = await getPosts();
const pinned = posts
.filter((post) => post.data.featured)
.sort((a, b) => (a.data.featuredOrder ?? 999) - (b.data.featuredOrder ?? 999));
const fill = posts.filter((post) => !post.data.featured);
return [...pinned, ...fill].slice(0, limit);
}
Posts with a featuredOrder come first in that order; pinned posts without one follow (they share 999, so the stable sort keeps them newest first). If you pin fewer posts than limit, the newest unpinned posts fill the gap. The draft filter is in getPosts(), so a draft can never be featured by accident; see draft posts in Astro.
Show them on the homepage
---
// src/pages/index.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import { getFeatured, getPosts } from '../lib/posts';
const featured = await getFeatured(3);
const featuredIds = new Set(featured.map((post) => post.id));
const latest = (await getPosts()).filter((post) => !featuredIds.has(post.id)).slice(0, 6);
---
<BaseLayout title="Home">
<section aria-labelledby="featured-heading">
<h2 id="featured-heading">Featured</h2>
<ul class="grid gap-6 md:grid-cols-3">
{featured.map((post) => (
<li>
<a href={`/blog/${post.id}/`}>
<h3>{post.data.title}</h3>
<p>{post.data.description}</p>
</a>
</li>
))}
</ul>
</section>
<section aria-labelledby="latest-heading">
<h2 id="latest-heading">Latest</h2>
<ul>
{latest.map((post) => (
<li><a href={`/blog/${post.id}/`}>{post.data.title}</a></li>
))}
</ul>
</section>
</BaseLayout>
The Set of featured IDs removes duplicates, so a pinned post that is also recent appears once. If your theme has a card component, use it here so featured posts look like the rest of the site; our component patterns for themes article shows how themes structure cards.
Keep the list short
Three featured posts is a good default: enough to fill one row on desktop, few enough that each one gets attention. If everything is featured, nothing is. Review the pinned posts every few months and unpin anything outdated, especially “this year” articles once the year ends.
For a larger visual treatment, give the first featured post a bigger card and the others smaller ones. That is a layout choice in the component; the data stays the same. Related ideas: related posts to keep readers moving at the end of an article, and sorting posts by date for the base ordering. The content collections docs cover schema options, and the Blog & Editorial themes show finished homepage layouts with featured sections.
FAQ
How do I feature a post in Astro?
Add a featured boolean to the collection schema and set featured: true in the post’s frontmatter. Then filter for it with getCollection() where you render the featured section.
Can I control the order of featured posts in Astro?
Yes. Add an optional number such as featuredOrder to the schema and sort pinned posts by it. Posts without a number fall back to date order.
What if no posts are featured?
With the fallback in getFeatured(), the newest posts fill the section. Without it, the section renders empty, so either add a fallback or hide the section when the list is empty.
Should featured posts appear in the latest posts list too?
Usually not on the same page. Remove featured IDs from the latest list so readers do not see the same post twice.