Blog Sections Open

Building a “You May Also Like” Block for Category Pages

A practical linking pattern for showing related category suggestions in a circular sequence, useful for internal linking and navigation blocks.

A common SEO request is a small internal-linking block such as “You may also like” or “You might be interested in”. In category-driven sites, that block usually needs predictable logic rather than random links.

The requirement from the original case

  • show three suggestions
  • link neighboring subcategories within the same section
  • for the current category, show one previous item and two following items

Why a raw &where attempt often fails

The original experiment tried to hard-code id-1, id+1, and id+2 inside a menu query. That rarely works reliably because document IDs are not sequence-safe navigation keys. Content can be deleted, moved, or created out of order.

A better approach

Build the list from actual sibling resources under the same parent and use menuindex or an explicit ordering field. Then calculate the previous and next items in PHP or in a helper snippet.

<?php
$siblings = $modx->getCollection('site_content', [
    'parent' => $parentId,
    'published' => 1,
    'deleted' => 0,
]);
// sort siblings by menuindex, find current item, then select
// one previous and two next items with wrap-around if needed.
?>

Why this is safer

  • it survives content reordering
  • it matches real section structure
  • it gives you deterministic internal linking

For simple menus you can still render the final output through a chunk or DocLister-style template. The important part is not to treat database IDs as if they were editorial sequence numbers.

Newer post

Troubleshooting FormLister Mail Delivery on Timeweb

A short troubleshooting guide for cases where FormLister suddenly stops sending mail on Timeweb or a similar hosting environment.

Older post

The New ManagerManager and Why It Still Matters

An extras spotlight on the renewed ManagerManager direction and why manager-level customization remained important for Evolution CMS teams.