Related Posts
A compact end-of-post list of related articles your template selects; the current post is always excluded.
Installation
Track the file-only install in a supported Payload project:
npx payload-components add related-postsWhat it installs
Copies 1 source file into your project:
src/components/RelatedPosts/Component.tsx
This file-only article component adds no Pages registration, renderer mapping, or generated files. Compose it in your article template using the example below.
Re-running the CLI install detects existing source and wiring, then records install state in .payload-components/state.json.
Content model
These are React props supplied by your post template. This component adds no collection fields and does not query, rank, or recommend content: your template selects the posts and passes them in display order. Resolve relationship IDs before supplying public display data.
Prop
Type
Each entry in posts carries:
Prop
Type
Usage
Import the component into your article template and pass public display content as props. The install adds no admin fields. Your template controls content loading and publishing.
import { RelatedPosts } from '@/components/RelatedPosts/Component'
import { Media } from '@/components/Media'
import type { Post } from '@/payload-types'
// Render once at the end of your post template, after the article body.
export function ArticleRelatedPosts({ post }: { post: Post }) {
return (
<RelatedPosts
currentHref={`/posts/${post.slug}`}
posts={(post.relatedPosts ?? []).flatMap((related) =>
typeof related === 'object' && related?.slug
? [
{
title: related.title,
href: `/posts/${related.slug}`,
excerpt: related.meta?.description,
publishedAt: related.publishedAt,
image:
related.meta?.image && typeof related.meta.image === 'object' ? (
<Media resource={related.meta.image} />
) : undefined,
},
]
: [],
)}
/>
)
}Place it once per post, after the article body and any author card. It renders a section labelled by its h2, with an h3 per post, so the page keeps the single h1 from your post header. When no posts remain after the current post, unsafe hrefs, and repeats are removed, it renders nothing, so the template needs no empty check. The Payload website starter ships its own RelatedPosts in @/blocks/RelatedPosts/Component. This install leaves that file alone, so swap the import in your post page or alias one of the two.
Selection stays in your template. The example reads the starter's manually curated relatedPosts relationship, which its post query populates at depth: 2. Automatic recommendations, such as recent posts that share a category, belong in a separate query that passes its results through the same posts prop. This component never queries, ranks, or fills the list.
Requirements
- Target
- payload-website-starter, payload-blocks-app
- Payload
- v3 / v4
- Next.js
- 15 / 16
- shadcn UI
- none
Direct shadcn installation needs React 19 and Tailwind with your theme tokens; this component has no Payload runtime imports. The targets above apply to CLI install tracking.
Your project must already expose components.json, src/payload.config.ts — the host shape checked by payload-components add. The CLI verifies this against the support matrix before touching anything.