These instructions will help you create a View of related nodes (based on shared taxonomy terms) in order of relevance. Nodes that share more terms with the current node are shown at the top of the list. For example, if you have a node IPhone 4S node with terms Gadget, Apple, and Phone, you can get similar nodes in the following order:
IPhone 3 (Apple, Gadget, Phone)
IPad (Apple, Gadget, Tablet)
Mac (Apple, Computer)
Bramley (Apple, Fruit, Tree)
To create the View:
- 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
Created with Drupal 7, Views 7.x-3.3 -- Click to enlarge |
Credits: From my answer on Stackoverflow
No comments:
Post a Comment