Skip to content
Wagtail Wagtail + CodeRed Extensions
  • Getting Started
    • Installation
    • Customize the design of your website
    • Tutorial Part 1: Site Name, Logo, and Basics
    • Tutorial Part 2: Adding Content
    • Tutorial Part 3: Navbar & Footer
    • Tutorial Part 4: Creating a Blog
    • Tutorial Part 5: Web Page
    • Tutorial Part 6: Create Categories with Classifiers
    • Tutorial Part 7: Forms & Contact Pages
    • Tutorial Part 8: SEO Metadata
    • Tutorial Part 9: Images
    • Tutorial Part 10: Password-Protected Pages
  • Advanced Tutorial
    • Customizing HTML/CSS in Templates
    • Custom Page Types
  • Features
    • Blocks
      • Content Blocks
        • Accordion Block
        • Button Block
        • Card Block
        • Carousel Block
        • Download Block
        • Embed Media Block
        • Film Strip Block
        • Google Map Block
        • HTML Block
        • Image Block
        • Image Gallery Block
        • Image Link
        • Latest Pages Block
        • Modal Block
        • Page Preview Block
        • Price List Block
        • Quote Block
        • Reusable Content Block
        • Table Block
        • Text Block
      • Layout Blocks
        • Card Grid Block
        • Column Block
        • Hero Block
        • Responsive Grid Row Block
    • Import Pages
    • Mailchimp Integration
    • Page Types
      • Article Pages
      • Event Pages
      • Form Pages
      • Location Pages
      • Stream Forms
      • Web Pages
    • Related Pages
    • Searching
    • Snippets
      • Accordions
      • Carousels
      • Classifiers
      • Content Walls
      • Film Strip
      • Footers
      • Navigation Bars
      • Reusable Content
  • How-To Guides
    • Best Practices for Images
    • Customize Navbar and Footer
    • Add Tracking Scripts
    • Open External Links in New Tab
    • Translation & Multi-Language Support
    • Run Wagtail CRX with Docker
    • Using a Custom Image Model in Wagtail CRX
    • Convert Existing Site to Use a Custom Image Model
  • Technical Reference
    • Wagtail CRX Django Settings
  • Contributing
  • Release Notes
    • v2.1.2 release notes
    • v2.1.1 release notes
    • v2.1.0 release notes
    • v2.0.0 release notes
    • v1.0.3 release notes
    • v1.0.2 release notes
    • v1.0.1 release notes
    • v1.0.0 release notes
    • v0.25.2 release notes
    • v0.25.1 release notes
    • v0.25.0 release notes
    • v0.24.1 release notes
    • v0.24.0 release notes
    • v0.23.1 release notes
    • v0.23.0 release notes
    • v0.22.3 release notes
    • v0.22.2 release notes
    • v0.22.1 release notes
    • v0.22.0 release notes
    • v0.21.1 release notes
    • v0.21.0 release notes
    • v0.20.0 release notes
    • v0.19.1 release notes
    • v0.19.0 release notes
    • v0.18.2 release notes
    • v0.18.1 release notes
    • v0.18.0 release notes
    • v0.17.0 release notes
    • v0.16.3 release notes
    • v0.16.2 release notes
    • v0.16.1 release notes
    • v0.16.0 release notes
    • v0.15.2 release notes
    • v0.15.1 release notes
    • v0.15.0 release notes
    • v0.14.1 release notes
    • v0.14.0 release notes
    • v0.13.3 release notes
    • v0.13.2 release notes
    • v0.13.1 release notes
    • v0.13.0 release notes
    • v0.12.1 release notes
    • v0.12.0 release notes
    • v0.11.0 release notes
    • v0.10.0 release notes
    • v0.9.1 release notes
    • v0.9.0 release notes

Get Pro Support
This project is commercially supported by CodeRed.

  1. Docs
  2. Features
  3. Related Pages
Edit on GitHub View source

Related Pages¶

Using the power of Classifiers, pages can automatically show a list of similarly classified pages. By default, this is enabled on Article Pages, but can be enabled on any page via the Wagtail Admin, or a 1-line code change on the page model.

Related pages showing similarly classified articles.

Related pages showing similarly classified articles.¶

Related page formatting¶

Each related page is rendered using the page model’s “miniview” template. The template can be overridden per model with the miniview_template attribute, the default of which is coderedcms/pages/page.mini.html.

If related pages are enabled, a QuerySet of pages is added to the context as related_pages. This QuerySet can also be retrieved by calling page.get_related_pages().

Related page customization¶

Each page can have related pages turned on or off via a toggle in the page editor, under the Layout tab. Pages based on CoderedArticlePage have this setting enabled by default when new pages are created. To toggle the default value when creating new pages, set related_show_default to True or False. To retroactively toggle this setting on existing pages, set the related related_show field using a manual query or migration.

By default, sibling pages are queried and ordered based on the number of Classifier Terms in common. If you wish to query a different model — for example to have Article pages show related Product pages instead — set the related_query_pagemodel attribute to the desired content type.

class ProductPage(CoderedPage):

    # Custom template that will be used when a Product
    # is shown on an Article page (below).
    miniview_template = "website/pages/product.mini.html"

class ArticlePage(CoderedPage):

    # Show related pages by default when creating new Articles.
    related_show_default = True

    # By default, related sibling Articles will be shown.
    # Show related Products instead.
    related_query_pagemodel = "website.ProductPage"

If you’d instead prefer to totally customize the related algorithm, override the get_related_pages() function. Just be sure to return a QuerySet of pages.

class ProductPage(CoderedPage):
    price = models.DecimalField(max_digits=9, decimal_places=2)

class ArticlePage(CoderedPage):

    # Show related pages by default when creating new Articles.
    related_show_default = True

    def get_related_pages(self) -> models.QuerySet:
        """Show most expensive products first."""
        return ProductPage.objects.live().order_by("-price")

New in version 2.1: You must be on Wagtail CRX version 2.1 or higher to use related pages.

← Web Pages Searching  →

Page contents

  • Related Pages
    • Related page formatting
    • Related page customization
  • Wagtail Hosting by CodeRed
  • Wagtail CRX on GitHub
  • About CodeRed

Wagtail Sphinx Theme 6.0.0

© Copyright 2018–2023, CodeRed LLC