Related content by term
Site visitors would like to see content related to a specific state/territory. To do this, we need to set up an automatically generated list of States/Territories in a block with the following features:
  1. 1.
    When we click on a term such as “ACT” we go to a term listing page that shows all content tagged or categorised with that term.
  2. 2.
    If we then select a specific article such as “Volunteering” we see the full content page.
  3. 3.
    In the sidebar of the “Volunteering” full node page we also see a “related content” block. This will pull in a list of content that’s been tagged or categorised with the same taxonomy term.
In the following exercises we'll make a “list of terms” block and then we'll make the related content block.

Exercise 6.5: Make a list of States/Territories block

In this exercise we’ll add a list of the States and Territories in the sidebar, so the page looks like the screenshot below.
  1. 1.
    Go to StructureViews. Click + Add new View. Add in these settings:
  • View name: States/Territories
  • Select to enable Description: A list of State and Territory terms
  • Show Taxonomy terms of type State/Territory sorted by Unsorted
  • Select Create a block
  • Block title: States/Territories
  • Display format: HTML list of Fields
  • Items per block: 0
  • Use a pager: Leave unselected
  • Click Save and edit
  1. 1.
    Go to Structure → Block Layout.
  2. 2.
    In the Sidebar area click the Place block button.
  3. 3.
    Find States/Territories block in Lists (Views) category and click the Place block button.
  4. 4.
    Configure block visibility settings to only display it on the Job Posting content type.
  5. 5.
    Click Save block.
  6. 6.
    Navigate to a Job posting content page and locate your block.
Next we’ll add the related content block, as per the screenshot below.
  1. 1.
    Check content tags
Make sure you have some content tagged with the State/Territory terms.
Create the View
Click Save and edit.
Add dynamic "contextual" filter
The contextual filter allows us to show a list of the content with the same tags as the current content.
Place the block
  1. 1.
    Go to StructureBlocks and scroll down to the “Sidebar” area
  2. 2.
    Click the Place block button.
  3. 3.
    In the pop-up, filter by text “Related content” in the Lists (Views) category.
  4. 4.
    Place block.
  5. 5.
    Under Visibility settings, configure block to display on all pages except the homepage. Remember to use the <front> token as the homepage identified. You may also use “/”. In addition, filter the block to only show on the following content types:
Job Posting
    1. 1.
      Click Save block.
Review and test
Go to the frontend of your site and check that the Related content block has been added, as in the below screenshot.
Check that you have some content in certain states/territories, so you can see how the block works.
  • When you click on a state (tag) on a specific article you should see a list of related content, listed by the taxonomy term. You should not see the block.
  • You should see the Related Content block when you view a job posting or News and Media article.
Filter out currently displayed page
While testing the Related content block, did you notice anything unusual?
The Related content block displays the article title of the currently displayed page:
Let’s remove it by adding one more Contextual Filter.
  1. 1.
    Return to editing the Related Content view.
  2. 2.
    Expand the Advanced pane and you should see the Contextual Filter Content: Has taxonomy term ID that we created earlier.
  3. 3.
    Add another contextual filter
  4. 4.
    Search for ID.
  5. 5.
    Select Provide default value in the When the filter value is NOT available pane → Content ID from URL.
  6. 6.
    Under the More pane, select Exclude
  7. 7.
    Apply the changes.
  8. 8.
    Save the View.
  9. 9.
    Test your block from the previous example. Now it shouldn’t display the current page in the block.
Export as PDF
Copy link