You are here

function taxonomy_breadcrumb_node_get_lightest_term in Taxonomy Breadcrumb 5

Return lightest term for given node ($nid). Similar to taxonomy_node_get_terms, but only return the lightest term in the lightest vocab for the node.

1 call to taxonomy_breadcrumb_node_get_lightest_term()
taxonomy_breadcrumb_nodeapi in ./taxonomy_breadcrumb.module
Implementation of hook_nodeapi().

File

./taxonomy_breadcrumb.module, line 45
The taxonomy_breadcrumb module generates taxonomy based breadcrumbs on node pages and taxonomy/term pages. The breadcrumb trail takes on the form: [HOME] >> [VOCABULARY] >> TERM >> [TERM] ...

Code

function taxonomy_breadcrumb_node_get_lightest_term($nid) {

  // We only want the first row of the result--this is the lightest term of the
  // lightest vocab.  This query should be the same as the query found in
  // taxonomy_node_get_terms.
  $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.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
  $term = db_fetch_object($result);

  // extract first row of query
  return $term;
}