Related Content
The related content feature lets you display a list of relevant items at the bottom of any article, page, or project. It works in two modes: manual curation or automatic scoring.
Enabling related items
In the editor sidebar, check Show related content on the item. This sets show_related_items: true in the item's JSON file. Nothing is rendered if this flag is false — there is no global default.
Manual mode
If you fill in the Related content field in the editor, those exact items are used. The stored format is an array of {type, slug} references:
{
"show_related_items": true,
"related_items": [
{ "type": "article", "slug": "my-other-article" },
{ "type": "project", "slug": "my-project" }
]
}
The slugs are resolved against the index at render time. If a referenced item no longer exists, it is silently skipped.
Auto mode
If related_items is empty, the algorithm scores all other content items across all three types (articles, pages, projects):
| Match | Score |
|---|---|
| Same category | +2 |
| Each shared tag | +1 |
Items with a score of 0 are excluded. Results are sorted by score descending, then limited to $limit (default: 5). Only index data is read — no full item files are loaded, so this is fast regardless of catalogue size.
Rendering in templates
// In content-articles.php, content-pages.php, content-projects.php
echo render_related_items($item);
// Limit auto mode to 3 results
echo render_related_items($item, 3);
render_related_items() returns empty string if show_related_items is not true, or if no candidates are found.
Generated HTML
<section class="related-items">
<h3 class="related-items-title">Related Content</h3>
<ul class="related-items-list">
<li class="related-item related-item--article">
<a href="…">
<span class="related-item-type">Article</span>
Title of the related article
</a>
</li>
</ul>
</section>
Style .related-items, .related-items-list, .related-item, and .related-item-type in your theme's style.css.
Notes
The $limit parameter only applies to auto mode. In manual mode, all referenced items are displayed regardless of the limit.
The title string ("Related Content") is translatable via __t('related_content', 'Related Content').
