I took a look at the similar terms module, but since it is only listing the node title, and i need more flexibility, i would like to create a view that does the same thing. Does anyone know of a good tutorial on setting up agruements that reference the current node's taxonomy terms and filters results based on this? I have products and would like to show products with similar keywords, specifications, etc.

Many thanks

Comments

damiandab’s picture

Looking for the same solution!!

damiandab’s picture

AvalancheOfLlamas’s picture

The argument you want in this kind of view is Node: ID and select Default argument -> from URL. This will load only the node you're currently viewing.

Then, create a relationship for taxonomy:related terms (the one with the description "Relate nodes to taxonomy terms..."). This will load all the terms that are tagged to that node.

Next we want to load all the nodes tagged with the terms we just loaded with that relationship. So, add a new relationship for taxonomy: node, and at the top of its settings, under Relationship:, select the relationship you just created.

Now you can start adding your fields. Add a node: title field if you want that function (I also like using it to test my view), and remember to "use" the node relationship that we just created by selecting it in the field's settings (you'll want to do this for all your fields).

Note that this loads ALL nodes tagged with ALL tags from the currently viewed node. Unsurprisingly, this loads the currently viewed node also! So in your "similar content," you'd see the page you're already on. To stop this, we can use arguments again.

So, we want to exclude the current page from the nodes loaded in our "node" relationship.
Add an argument for Node: ID again, but this time, "use" the node relationship that we have. Once again make it a default argument, Node ID from the URL, but this time, scroll down and check off the "exclude this argument" checkbox. This will make the argument be, well, excluded (pretty self-explanatory).

Make it a block (add a block display), put it in a region under site building -> blocks (you also might want to restrict the pages it's on), and viola!

NOTE: When you preview the view, you'll have to enter a node id into the little arguments field. Since you have two arguments, you need to type in 346/346 (for node id 346, for example). Never fear though, both arguments will work if your URL is simply node/346 and not node/346/346. Just a weird thing in the way views are previewed.

Hope that helps
Alan

oobie11’s picture

Alan, you sir are a god. I have been struggling with this for way too long and you have lifted my burden. Thank you.

TrevorG’s picture

Alan, thank you very very much. The modules for d7 I have tried that do this either are too limited in functionality or are broken. Also, because of your example I learned about using Views arguments and relationships, which helped me to circumvent another Drupal limitation.