Articles


How to display related nodes in a block based on taxonomy terms with Views 3 and Drupal 7

How to display related nodes in a block based on taxonomy terms with Views 3 and Drupal 7



Posted byJibin Jose,22nd Dec 2015

For one of my Drupal 7 sites need to show a related node block view inside the node page to redirect the user to the next node having the same taxonomy instead of moving from the home page. 

For creating the related nodes as a block. We need to add a new views block for doing the same. Drupal view is very vast but creating a view is very simple. Please follow the below steps for creating a new view block and adding the filter options for creating the view along with the same taxonomy terms of a particular node view.

Steps: 

Create a view (block) [admin/structure/views/add]

  Ref Img :

  There we can find the option to add the block title and description of the particular block. 

  There we can find the options to add the format of particular block [Eg: grid slider etc.]

  Save the block.

 

Add the required field for the block title, image or body depends on your requirement. 

The above are the basic steps for a simple views block. 

Add the filter option for getting related node with respect to the taxonomy terms.

Click on the Advanced option in the block. 

 

  Add the Contextual filters

 

  Add the filter option : Content: Has taxonomy term ID (with depth) and Content: Has taxonomy term ID depth modifier

Configure the filter :

  Configuration of this filter: → When the filter value is NOT in the URL: → Provide a default value → Type: Taxonomy Term ID from URL → under that, check the box “Load default filter from node page, that’s good for related taxonomy blocks.” 

  Add the taxonomies you want to list from the group of all taxonomies.

Exclude the current node from the list.

Click on the add button on the contextual filter.
  
 

  In the  view settings, choose "Provide a default value" again, but this time select "Content ID from URL" since want to grab the ID of the current article.

  Search and add the Content: Nid

  Add the condition ‘when argument is not present’ to ‘Provide default argument’
  
  Set the ‘Default argument type’ to ‘Content ID from URL’

  Go to “MORE” , and check the “Exclude” box.

  Move the filter “Content: Nid” to the top position.

  Save the block and show the block inside the region where we need to list the block.

By the above step we can easily create a view block to list related nodes having the same taxonomy term of a particular block.

Categories