Create a Related content block with taxonomy terms with Views 3 and Panels 3

On each "bookmark" page on this website, you will see a block with related blog article at the bottom.

Each bookmark is a node template created with Page manager (Showing a short version of the original article). I encountered some problems to display all the related blog article when a bookmark contained multiple tags. In this article, I describe step by step how I fixed this problem.

Prerequisite 

 

How-to

1. Create a "Tags" vocabulary and insert some terms

2. Add a "Tags" taxonomy field to the Articles content type with 'auto complete' and number of fields 'Unlimited' - (admin/structure/types/manage/article/fields)

3. Create a "Related blog content" with machine name "related_content_block" - (admin/structure/views/add)

  • Show fields of your blog content type (Title, Created date, body summary, ...) sorted by "Post date (desc)"
  • Unformatted list of 'fields'
  • Add a context filters : "Content: Has taxonomy term ID"

For "Content: Has taxonomy term ID" Set "WHEN THE FILTER VALUE IS NOT AVAILABLE" to:

  • Provide default value : "Taxonomy from URL", and "Load default filter from node page"
  • Vocabulary : Tags
  • Multiple-value handling : "Filter to items that share any term"
 
For "Content: Has taxonomy term ID" Set "WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED" to:
 
  • Specify validation criteria - Validator > Taxonomy Term
  • Vocabulary : "Tags"
  • Filter value type - Term IDs separated by , or +
  • More - Check the box for "Allow multiple values"

4. In Page manager, create a node template to display a bookmark page (including a short version of the original article) :

  • Selection Rules - Node Type: "Bookmark" > All criteria must pass.
  • Contexts > Relationships - Multiple Terms from Node > select "Tags" vocabulary -  using Concatenator + (OR) or , (AND) (be careful as you guess this option as an impact when you have a multiple tags for a Bookmark)
  • Choose Layout - Any
  • Panel Settings - Default
  • Inside the Panel Content tab (under the main bookmark view), Add Content > Views > "Related blog content" > Content: Has taxonomy term ID > Multiple Terms from Node > Term ID of all term, separated by + or ,
  • Then "Create Variant"

5. Create a Bookmark with many existing tags, and it should display a block with related blog articles.

Sources :  Contextual filter: Has taxonomy term ID doesn't work with multiple terms

About the author

Consultant, Web strategist, and Drupal enthusiast, I use open source software to build application that connects people and spread ideas. I believe that internet can lead to powerful changes for progressive organizations, and for our future.

Keep in touch here