function taxonomy_tools_term_path in Taxonomy Tools 8
Same name and namespace in other branches
- 7 taxonomy_tools.module \taxonomy_tools_term_path()
Returns full parent hierarchy of taxonomy term.
Parameters
string $tid: Taxonomy term identificator.
Return value
array An array representing full hierarchy of taxonomy term.
1 call to taxonomy_tools_term_path()
- taxonomy_tools_preprocess_page in ./
taxonomy_tools.module - Implements hook_preprocess_HOOK().
File
- ./
taxonomy_tools.module, line 418 - Drupal hooks and functions to work with taxonomy terms.
Code
function taxonomy_tools_term_path($tid, $return = TRUE) {
$path = array();
$query = db_select('taxonomy_term_data', 'foo');
$query
->addField('foo', 'name');
$query
->condition('foo.tid', $tid);
$query
->leftJoin('taxonomy_term_hierarchy', 'bar', 'foo.tid = bar.tid');
$query
->addField('bar', 'parent');
$result = $query
->execute()
->fetchObject();
if ($return) {
$path[] = array(
'tid' => $tid,
'name' => $result->name,
);
}
if ($result->parent > 0) {
$path = array_merge($path, taxonomy_tools_term_path($result->parent));
}
return $path;
}