Drupal 7: Show Related Content
Posted by Wayne on Tuesday, 11 March 2014
A handy bit of Views hackery in Drupal 7. Of all the things Drupal does out of the box, this is probably the most suprising thing it doesn't do.
- Create a block view
- Add Contextual filter -> Content: Nid -> Provide default value -> Content ID from URL
- Add Relationship -> Content: Taxonomy terms on node -> specify the appropriate vocabulary
- Add Relationship -> Taxonomy term: Content using vocabulary as specified above -> Check off Require this relationship
- Turn on Views aggregation
- Assuming you are listing title only, edit the title field to use the Relationship you set up in #4 above.
- Add new sort criteria of Content: Nid. In aggregation settings, select Count. Use relationship from #4 and sort descending
- Add Contextual filter -> Content: Nid -> Use relationship from #4 -> Provide default value - Content ID from URL -> Scroll down and expand "More" then check "Exclude" to remove current node from the view