Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Note: This answer is subset of the answer I provided at http://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670https://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670 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.

Note: This answer is subset of the answer I provided at http://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670 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.

Note: This answer is subset of the answer I provided at https://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670 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.

added 2864 characters in body
Source Link
mohit_rocks
  • 4k
  • 2
  • 25
  • 60

You can get the taxonomy term id fromThis 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 usingthis video http://mustardseedmedia.com/podcast/episode37

Now we get to Views attach. Please enable the views attach module before proceeding. Essentially var_dump($node) findViews attach attaches a view at the term idend of thatthe node. In our case our view will be a listing of other articles with the same term.

After findingWe will essentially need to "pass" the termid usetaxonomy term of the node to the view. Let the name of your Vocabulary be called taxonomy_select_nodes()MyVocab. This returns nodes attached

Steps to a term across all field instancesmake the view.

  1. Lets call the view display_other_articles_with_same_taxonomy.
  2. Add a display of type 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 Display

Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No

You should select Use tokens from the node the view is attached to under Arguments. Let the token be [term-id] This function requires taxonomy moduleis the "ID of top taxonomy term". This is very important!! Essentially you are going to be maintaining its own tables, and will return an empty array if it is notpassing the taxonomy term of the node from the MyVocab (See http://groups.drupal.org/node/11788#comment-38332). If using other field storage methods alternatives methods for listing termsit has the lowest weight, the taxonomy vocabulary will need to be usedthe first vocabulary in the taxonomy section of your node edit form. Add an argument Taxonomy: Term Id.

AndAdd the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node

So what this view is going to do is:

  1. Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
  2. Pass that as argument to the view display_other_articles_with_same_taxonomy
  3. List all the nodes that have the same taxonomy term as the node being displayed.

Thats it will return!

If you're using Views 3 (currently at alpha3 at the arraytime of matching Nids for particularwriting) 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:

  1. Forget about views attach... its not required
  2. Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
  3. You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action 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 page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
  4. Make sure you name the block and put it in the appropriate region.

Note: This answer is subset of the answer I provided at http://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670 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.

You can get the taxonomy term id from by using the var_dump($node) find the term id of that node.

After finding the termid use taxonomy_select_nodes(). This returns nodes attached to a term across all field instances.

This function requires taxonomy module to be maintaining its own tables, and will return an empty array if it is not. If using other field storage methods alternatives methods for listing terms will need to be used.

And it will return the array of matching Nids for particular term.

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 attach attaches 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.

  1. Lets call the view display_other_articles_with_same_taxonomy.
  2. Add a display of type 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 Display

Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No

You should select Use tokens from the node the view is attached to under 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 the MyVocab (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 argument Taxonomy: Term Id.

Add the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node

So what this view is going to do is:

  1. Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
  2. Pass that as argument to the view display_other_articles_with_same_taxonomy
  3. List all the nodes that have the same taxonomy term as the node being displayed.

Thats 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:

  1. Forget about views attach... its not required
  2. Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
  3. You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action 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 page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
  4. Make sure you name the block and put it in the appropriate region.

Note: This answer is subset of the answer I provided at http://stackoverflow.com/questions/3895213/how-to-just-show-nodequeue-block-on-included-nodes/3909670#3909670 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.

Source Link
mohit_rocks
  • 4k
  • 2
  • 25
  • 60

You can get the taxonomy term id from by using the var_dump($node) find the term id of that node.

After finding the termid use taxonomy_select_nodes(). This returns nodes attached to a term across all field instances.

This function requires taxonomy module to be maintaining its own tables, and will return an empty array if it is not. If using other field storage methods alternatives methods for listing terms will need to be used.

And it will return the array of matching Nids for particular term.