In this drupal tutorial we will learn how to show related articles / posts on a Drupal 8, 9 and 10 website. We will not use any additional module for this. We will only use view module, which is a Drupal core module. Related posts will be posts from the same category.
The related posts are designed to be placed below the main article. Your site visitors might be interested in reading these related posts.
Step 1: Create View
Create a new view that will display related posts.
Administration >> Structure >> Views
Click Add view button.
Step 2: View Settings
Use below view settings for creating the view.
- View name: Related Posts
- Show: Content of type Article shorted by Newest first
- Block Settings: Unformatted list of titles (linked)
Step 3: Add Contextual filters
Under Advanced section, add a Contextual filters.
Select Has taxonomy term ID and click Add and configure contextual filters
Step 4: Configure contextual filter
- Select Provide default value
- For Type select Taxonomy term ID from URL
- Also select Load default filter from node page, that's good for related taxonomy blocks
- And select Limit terms by vocabulary and select the Vocabulary that you use for categorising articles.
Step 5: Place the block.
We are almost done. Now we will place this view block below the content.
Administration >> Structure >> Block layout
And place this newly created view block Related Posts below Main page content.
Step 6: Clear cache
We may need to clear Drupal cache.
Navigate to below and clear cache.
Administration >> Configuration >> Development >> Performance
Open any article page and you should find the Related Posts below the page content.