taxonomy_node_get_terms

Versions
4.6 – 5
taxonomy_node_get_terms($nid, $key = 'tid')
6
taxonomy_node_get_terms($node, $key = 'tid')

Find all terms associated with the given node, ordered by vocabulary and term weight.

▾ 2 functions call taxonomy_node_get_terms()

taxonomy_form_alter in modules/taxonomy/taxonomy.module
Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node. We check for taxonomy_override_selector before loading the full vocabulary, so contrib modules can intercept before hook_form_alter and provide scalable...
taxonomy_nodeapi in modules/taxonomy/taxonomy.module
Implementation of hook_nodeapi().

Code

modules/taxonomy/taxonomy.module, line 612

<?php
function taxonomy_node_get_terms($node, $key = 'tid') {
  static $terms;

  if (!isset($terms[$node->vid][$key])) {
    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $node->vid);
    $terms[$node->vid][$key] = array();
    while ($term = db_fetch_object($result)) {
      $terms[$node->vid][$key][$term->$key] = $term;
    }
  }
  return $terms[$node->vid][$key];
}
?>

View taxonomy terms in node sorted by multiple group

Evgenij - Sun, 2009-09-13 16:21

View taxonomy terms in node sorted by multiple group.

For example:

(Freetagging)
Tags:
books
authors
etc.

and

(Defined category)
Category:
Books

..................................................................................................

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
 
$node = node_load(arg(1));
  foreach (
$node->taxonomy as $vid => $term) {
 
$vn = taxonomy_vocabulary_load($term->vid);
 
$t[$vn->name][$term->tid]['name'] = $term->name;
}
 
$output = '';
  foreach (
$t as $key => $value){
 
$output .= '<fieldset class="fieldgroup collapsible"><legend>'.$key.'</legend>';
  foreach(
$value as $b => $a){
 
$output .= '<div class="field-item odd">';
 
$output .= l($a['name'], 'taxonomy/term/' . $b) . ' ';
 
$output .= '</div>';
}
 
$output .= '</fieldset>';
}
  print
$output;
}
?>

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.