Adding A Related Content Block In Drupal 7

Before you begin make sure that your view is a block. Once you have a block view follow the steps below to set up your related content block.

Step 1: Add Relationships

Two relationships must be added:

  1. Entity Referenced: Referenced Entity
  2. Entity Referencing: Referencing Entity

The Referencing Entity must reference the first relationship, the Referenced Entity. This creates a circular relationship.

Step 2: Add Contextual Filter Using Second Relationship

The next steps tell the View to only display content that share the same entity, such as all interactions with the same contact in my case.

  1. Add a Contextual Filter using Node ID (Nid) that uses the Referencing Entity relationship
  2. Select Provide default value and choose Content ID from URL

Step 3: Exclude Your Current Node

If you stop after step 2, you’ll see a duplicate node in your block. So if I’m looking at notes from an interaction, that same interaction would appear in my block instead of only related nodes.

To exclude the node you’re on, follow these steps:

  1. Add another Contextual Filter using Node ID (Nid), but don’t select a relationship
  2. Select Provide default value and choose Content ID from URL
  3. Under the ‘More’ menu, select Exclude

Step 4: Choose ‘Distinct’ Option in Query Settings

As stated in the help text

“This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work.”

Step 5: Save Your View

Save your view and you now have a related content block view. You may now use this block and place it anywhere on your site.