There is no secret that related content can help to improve over all page views for website. More page views means more engaged website visitors, resulting in more sales and higher profit.
In today's Drupal tutorial I will write how to make related content block using taxonomy term field in Drupal 8. For Drupal 7 tutorial see: Related nodes based on taxonomy terms
In short, if you are already familiar how to create related content block in Drupal 7, there is no huge difference in Drupal 8. If you are new to Drupal, keep reading.
- Content type with taxonomy term enabled.
For this tutorial I will use live example from tourgeorgia.eu here we have content type Tour and attached taxonomy term field: Tour type. What we want to build is a related view listing related tours from the same category as given article, for example cultural tour.
Related taxonomy block in Drupal 8
You can see a live preview here
Drupal 8 views for related taxonomy term
Create a new content based block view - give it a nice name, Related Items (or something) add title, image and body fields to it. We will need to use 2 contextual filters. Id and Has taxonomy term id.
Configure Id filter as following:
- Provide default value: Content ID from URL
- Under More tab - Check next to Exclude
Configure Has taxonomy term id as following:
- Provide default value: Taxonomy term ID from URL
- Uncheck: Load default filter from term page
- Check next to: Load default filter from node page, that's good for related taxonomy block
- Multiple value handling: Filter to items that share any value
- Check next to Reduce Duplicates
- Under more tab check: Allow multiple values and Allow multiple values to work together.
That's it. Save your view (be sure you have created a block not page view). Now you just need to add block you just created to your sites theme region.
It is up to you have you will decide to theme your related items block. Sky is the limit for you creative work. You can add author field, date field, rating field.. so do you can add some filters to show most viewed related nodes content. In this example I gave to you, is just a basic to help you to get started for showing related item list on your Drupal powered site.
N.B. On my example Live preview from views page is not working, but it actually works when added to region in your theme.