I have a Content-Type with taxonomy-terms. It’s a select-list, so it can have only one taxonomy – at least of that vocabulary. Now I need to build a view that lists all nodes with the same taxonomy.
Thought that this wouldn’t be too hard since it sounds pretty basic. Yet I can’t get it working. Any ideas? I’m trying to avoid writing a module for this.
This answer works in Views version 2 or higher. First you need to install Views attach ( http://drupal.org/project/views_attach ). Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37
Now we get to Views attach. Please enable the views attach module before proceeding. Essentially
Views attachattaches a view at the end of the node. In our case our view will be a listing of other articles with the same term.We will essentially need to “pass” the taxonomy term of the node to the view. Let the name of your Vocabulary be called
MyVocab.Steps to make the view.
display_other_articles_with_same_taxonomy.Node Content(available after enabling Views attach). This is a display just like block and page displays but with special ability of attaching itself to the node.Make the following settings in the
Node Content DisplayYou should select
Use tokens from the node the view is attached tounder Arguments. Let the token be[term-id]This is the “ID of top taxonomy term”. This is very important!! Essentially you are going to be passing the taxonomy term of the node from theMyVocab(See http://groups.drupal.org/node/11788#comment-38332). If it has the lowest weight, the taxonomy vocabulary will be the first vocabulary in the taxonomy section of your node edit form. Add an argumentTaxonomy: Term Id.Add the fields you are interested in e.g.
Node: Title. Make sure theNode: Titleis made into a hyperlink by tickingLink this field to its NodeSo what this view is going to do is:
MyVocabvocabulary in the Node that is currently being vieweddisplay_other_articles_with_same_taxonomyThats it!
If you’re using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the articles have same taxonomy term come at the end of node body) you can do it in the following fashion:
Node Contentdisplay.Taxononomy: Term Idjust slightly: UnderAction to take if argument is not present:choose[x] Provide Default Argument. Choose[x] Taxonomy Term ID from URL. Now make sure[] Load default argument from term pageis unselected and[x] Load default argument from node page, thats good for related taxonomy blocks.Also[x]Limit terms by vocabularyand choose theSeriesvocabulary.Note: This answer is subset of the answer I provided at How to just show NodeQueue block on included nodes? In that scenario the requirement was that the related articles are explicitly selected and listed in a particular order. Its a little more complex and uses Nodequeues which we don’t need here at all.