Drupal 7 is a CMS and is used in designing applications and websites. Drupal 7 has become a favourite among the developers because of the several features that it offers. It is reliable, flexible, modular, offers easy content authoring and above all, it has an excellent security system. This article will teach you all about Drupal related content block. You will learn how to create a related content block in Drupal 7 which will reveal content related to the node that is being condensed on the page. Views and Entity Reference modules are required for this.
There are two steps in which Related Content Block in Drupal 7 is done:
There are two Content Types that are required – one is for the main node and the second one is the reference node. When you are aware of what you actually have to reference to what, the Entity Reference module will have to be installed.
In the tutorial below the main Content Type will be referred to Article AA and the content that has been referenced will be referred to as Related Content AA.
When the Entity Reference module is installed, you will need to add a new field to Article AA. For this, you need to go to
Next you would need to use either autocomplete for the widget or select the one you wish to use. The Content Type can be selected from the field setting, in the example here it is Related Content AA.
If you wish to see whether or not you are on the right track, you can create a test node of your Related Content AA. After which create a node of your Article AA. You will locate the recent addition of Entity Reference field in the edit form of the Article AA. Look for the Related Content node that has just been created and then save it. You will be able to see the link to the Related Content node that has recently been added in the Article node when you view the Article AA. If you are unable to view anything , check whether the newly added field has been set to be displayed in the ‘Full View’ mode.
You can go to
You can manage the display setting and set it if it is not in the correct mode.
Once this is done and can be seen on the node page you can go back and hide the recently added field from the display on all view modes of the Article AA. This content will then be displayed with Views in a block with the help of Contextual Filters.
The second step in creating Drupal related content block is installing the latest version of Views. After which a new View with block display showing just the Related Content AA needs to be created. Now towards the right open the
and then add a new
Click Apply and then on the next screen check the box-
and then add an Identifier according to your preference.
The next step is to add the Contextual Filter so the results can be displayed in this block which relate just to the Article AA.
Add a Centextual Filter of the type: Content: Nid and then click on Apply. In the next screen under Relationship, you have to select the Identifier of the Relationship that has been added in the Relationship section. Under,
you have to select
and as Validator select Content of type Article or whichever is your main content. Under Filter value format select Node ID and under
select Hide View. Now you can Apply, save the block and test.
The block should be added to a region. Now go back to the Article node and while viewing the node, the new block that you have created should display the title of the Related Content node you referenced in the Article node before.
There are many ways you can work with the new View block and customise it according to your wish or requirement.