This tutorial will teach you how to create in Drupal 7 a Related Content block that shows content related to the node that is being rendered on the page. To do this you'll need the Entity Reference and the Views modules. The relation between the nodes is made by a reference between the two, but can also be by sharing the same taxonomy terms.
So, you do this in two steps:
First, you logically need at least 2 Content Types: one for the main node and another as reference nodes. Once you know what you want to reference to what, you have to install the Entity Reference module.
For the purpose of this tutorial, I will refer to the main Content Type as Article CT and the referenced content as Related Content CT.
Once you installed the Entity Reference module, add a new field to your Article CT. Go to
Structure – Content Types – Article (or whatever your Content Type is) – Manage Fields – Add New Field – Entity Reference. For the widget, I used autocomplete (but you can choose which one to use). In the field setting, you can select the target Content Type, in this example the Related Content CT.
To test if this is working so far, create a test node of your Related Content CT. Then, create a node of your Article CT. In the edit form of the Article CT you should find your newly added Entity Reference field. Find the Related Content node you just created and then you can save the node. View the Article CT node and you should see a link to the Related Content node you just added to your Article node. In case nothing appears, check to see if the newly added field is set to display in the Full View mode. Go to
Structure – Content Types – Article (or whatever your Content Type is) – Manage Display and you can set it there in case it is not.
Once you checked and it appears properly on the node page, go back and hide the newly added field from the display on all view modes of the Article CT. You will display this content with Views in a block using Contextual Filters.
If you hadn’t already, install the latest version of Views and create a new View with a block display that shows only Related Content CT. On the right side, open the Advanced options and add a new Relationship of the type:
Entity Reference: Referencing entity (you’ll find the description underneath as being A bridge to the Content entity that is referencing Content via field_related_content – or whatever you named the Related Content field in the Article CT). Click Apply and on the next screen check the box:
Require this relationship” and add an Identifier to what you prefer.
Next you need to add the Contextual Filter in order to display results in this block that relate only to your Article CT.
Add a Contextual Filter of the type:
Content:Nid and click Apply. On the next screen, under Relationship, select the Identifier of the Relationship you had just added in the Relationship section. Below, under When the filter value is NOT available, select
Provide default value of the type
Content ID from URL.
Lower, under When the filter value IS available or a default is provided, check the
Specify the validation criteria box and as Validator select
Content of type
Article (or whatever your main content type is). Under Filter value format choose
Node ID and under Action to take if filter value does not validate choose
Hide View. Then you can Apply, save your block and test.
Add your block to a region and go back to your Article node and when viewing that node, your newly created block should display the title of the Related Content node you referenced in the Article node earlier. You can of course work a lot with that new View block and customise it as you please.
Hope this helps, good luck, and drop a comment if you didn’t understand something.