« Enable Keyword-Search Within a View

Drupal, How To

Show a list of items related to the current node

04.30.09 | Comment?

This mini tutorial guides you through the steps required to create a view that:

  1. determines which taxonomy terms are associated with the current node such as a news item
  2. combines these terms into a default View Argument for Term ID

The result is a list with nodes which match at least one of the terms. So if your node is linked to term A and B, the list will contain items linked to A or to B.

Versions used: Drupal 6.10 with Views 6.x-2.3

  • Create a View
  • Add a Field Node > Title
    • Remove the label and check: Link this field to its node
  • If you like, add Sort criteria such as Node: Title with Sort order: Ascending
  • Add an Argument Taxonomy > Term ID
    • Action to take if argument is not present: Provide default argument
    • Default argument type: PHP code
$node = node_load(arg(1));
if ($node->taxonomy) { // Does it have terms?
  foreach ($node->taxonomy as $term) {
    $terms[] = $term->tid;
  }
  return implode('+', $terms);
} else {
  return;
}
  • Validator: Default Validator
  • Allow multiple terms per argument: checked
  • Reduce duplicates: checked

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« Enable Keyword-Search Within a View