Skip to main content
added 4 characters in body
Source Link
Laxman13
  • 6.8k
  • 3
  • 30
  • 39

If I understand your question correctly, you can just use [Views][1] to accomplish this.

To display a block that lists other node titles with related taxonomy terms:

  1. Create a Block View
  2. Add the field Node:Title (make it link to its node)
  3. Add the argument Taxonomy: Term ID
  4. Configure this argument as follows:
  • Check Provide default argument
  • Select PHP Code
  • Add the following code:
$node`$node = node_load(arg(1));  
  if($node) {  
    if ($node->taxonomy) {  
      foreach($node->taxonomy as $term) { $terms[] = $term->tid; }  
      return implode('+',$terms);  
    }   
    else {  
      return;  
    }  
  }  
  else {   
      return;   
   } 
  }`
  • Check Allow multiple terms per argument
  • Check Reduce duplicates
  1. Now you need to add the second argument in order to exclude the current node from the list. Click [+] button of the arguments section.

  2. Select Node:Nid

  3. Set the "Action to take if argument is not present" to Provide default argument

  4. Set the "Default argument type" to Node ID from URL

  5. Check Exclude the argument

  6. Save your view

You can customize this however you like, such as filtering to a specific content type (ie "News"), can filter by post date, sort by: post date, random, etc.

For a whole discussion on this see http://drupal.org/node/65375

(Sorry for the poor code formatting, not sure how to format code inside a blockquote and list) [1]: http://drupal.org/project/views

If I understand your question correctly, you can just use [Views][1] to accomplish this.

To display a block that lists other node titles with related taxonomy terms:

  1. Create a Block View
  2. Add the field Node:Title (make it link to its node)
  3. Add the argument Taxonomy: Term ID
  4. Configure this argument as follows:
  • Check Provide default argument
  • Select PHP Code
  • Add the following code:
$node = node_load(arg(1));  
  if($node) {  
    if ($node->taxonomy) {  
      foreach($node->taxonomy as $term) { $terms[] = $term->tid; }  
      return implode('+',$terms);  
    }   
    else {  
      return;  
    }  
  }  
  else {   
    return;   
   }  
  • Check Allow multiple terms per argument
  • Check Reduce duplicates
  1. Now you need to add the second argument in order to exclude the current node from the list. Click [+] button of the arguments section.

  2. Select Node:Nid

  3. Set the "Action to take if argument is not present" to Provide default argument

  4. Set the "Default argument type" to Node ID from URL

  5. Check Exclude the argument

  6. Save your view

You can customize this however you like, such as filtering to a specific content type (ie "News"), can filter by post date, sort by: post date, random, etc.

For a whole discussion on this see http://drupal.org/node/65375

(Sorry for the poor code formatting, not sure how to format code inside a blockquote and list) [1]: http://drupal.org/project/views

If I understand your question correctly, you can just use [Views][1] to accomplish this.

To display a block that lists other node titles with related taxonomy terms:

  1. Create a Block View
  2. Add the field Node:Title (make it link to its node)
  3. Add the argument Taxonomy: Term ID
  4. Configure this argument as follows:
  • Check Provide default argument
  • Select PHP Code
  • Add the following code:
`$node = node_load(arg(1));  
  if($node) {  
    if ($node->taxonomy) {  
      foreach($node->taxonomy as $term) { $terms[] = $term->tid; }  
      return implode('+',$terms);  
    }   
    else {  
      return;  
    }  
  }  
  else {   
      return;      
  }`
  • Check Allow multiple terms per argument
  • Check Reduce duplicates
  1. Now you need to add the second argument in order to exclude the current node from the list. Click [+] button of the arguments section.

  2. Select Node:Nid

  3. Set the "Action to take if argument is not present" to Provide default argument

  4. Set the "Default argument type" to Node ID from URL

  5. Check Exclude the argument

  6. Save your view

You can customize this however you like, such as filtering to a specific content type (ie "News"), can filter by post date, sort by: post date, random, etc.

For a whole discussion on this see http://drupal.org/node/65375

(Sorry for the poor code formatting, not sure how to format code inside a blockquote and list) [1]: http://drupal.org/project/views

Source Link
Laxman13
  • 6.8k
  • 3
  • 30
  • 39

If I understand your question correctly, you can just use [Views][1] to accomplish this.

To display a block that lists other node titles with related taxonomy terms:

  1. Create a Block View
  2. Add the field Node:Title (make it link to its node)
  3. Add the argument Taxonomy: Term ID
  4. Configure this argument as follows:
  • Check Provide default argument
  • Select PHP Code
  • Add the following code:
$node = node_load(arg(1));  
  if($node) {  
    if ($node->taxonomy) {  
      foreach($node->taxonomy as $term) { $terms[] = $term->tid; }  
      return implode('+',$terms);  
    }   
    else {  
      return;  
    }  
  }  
  else {   
    return;   
  }  
  • Check Allow multiple terms per argument
  • Check Reduce duplicates
  1. Now you need to add the second argument in order to exclude the current node from the list. Click [+] button of the arguments section.

  2. Select Node:Nid

  3. Set the "Action to take if argument is not present" to Provide default argument

  4. Set the "Default argument type" to Node ID from URL

  5. Check Exclude the argument

  6. Save your view

You can customize this however you like, such as filtering to a specific content type (ie "News"), can filter by post date, sort by: post date, random, etc.

For a whole discussion on this see http://drupal.org/node/65375

(Sorry for the poor code formatting, not sure how to format code inside a blockquote and list) [1]: http://drupal.org/project/views