| 5 taxonomy.module | taxonomy_get_term($tid) |
| 6 taxonomy.module | taxonomy_get_term($tid, $reset = FALSE) |
Return the term object matching a term ID.
Parameters
$tid: A term's ID
$reset: Whether to reset the internal taxonomy_get_term cache.
Return value
Object A term object. Results are statically cached.
File
- modules/
taxonomy/ taxonomy.module, line 1083 - Enables the organization of content into categories.
Code
<?php
function taxonomy_get_term($tid, $reset = FALSE) {
static $terms = array();
if ($reset) {
$terms = array();
}
if (!isset($terms[$tid])) {
$terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
}
return $terms[$tid];
}
?> Login or register to post comments
Comments
custom breadcrumb in
custom breadcrumb in taxonomy/term/%tid
<?php
function YOURTHEME_breadcrumb($breadcrumb) {
if (arg(0) == 'taxonomy' && arg(1) == 'term') {
$tid = arg(2);
$term = taxonomy_get_term($tid);
$vocabulary = taxonomy_vocabulary_load($term->vid);
$vterms = taxonomy_get_tree($term->vid);
$vitems = '';
foreach ( $vterms as $vterm ) {
$vitems .= "+".$vterm->tid;
}
$breadcrumb[] = l($vocabulary->name, 'taxonomy/term/'.$vitems);
$breadcrumb[] = l($term->name, 'taxonomy/term/'.$term->tid);
}
if (count($breadcrumb) > 1) {
// $breadcrumb[] = drupal_get_title();
if ($breadcrumb) {
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) ."</div>\n";
}
}
}
?>
The above code helped me
The above code helped me greatly. Thank you for posting that - I've been trying to address it for days
Helper function to get taxonomy name from arg
You can use this in your themes to add additional information on your taxonomy/term/x pages ;
<?phpfunction get_tax_from_arg ($vid) {
if (arg(0) == 'taxonomy' && arg(1) == 'term') {
$tid = (int)arg(2);
if(is_numeric(arg(2))) {
$term = taxonomy_get_term($tid);
if(is_object($term)) {
if($vid == $term->vid) {
$name = $term->name;
return $name;
}
else return;
}
else return;
}
}
}
// use like this - print get_tax_from_arg(1), where 1 is vocabulary id
?>
D7
In Drupal 7, use taxonomy_term_load() .
http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...
Example code
in your theme's template.php (if you dont have one, please create one)
<?phpfunction getTermsName($taxnomyid){
$terms = taxonomy_get_term($taxnomyid);
$termsname = $terms->name;
return $termsname;
}
?>
now call the function wherever you want taxonamy termname from tern id
<?php$taxnomyid = 'term id you got';
echo getTermsName($taxnomyid);
?>
Happy Drupaling :)
No text
Nevermind...
How the returned object looks like
stdClass Object(
[tid] => 4646
[vid] => 3
[name] => video
[description] => Everything with a video.
[weight] => 0
)
Same Here!
This was a great help!!