Community Documentation

taxonomy_get_term

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.

▾ 11 functions call taxonomy_get_term()

forum_confirm_delete in modules/forum/forum.admin.inc
Returns a confirmation page for deleting a forum taxonomy term.
forum_get_topics in modules/forum/forum.module
forum_nodeapi in modules/forum/forum.module
Implementation of hook_nodeapi().
taxonomy_admin_term_edit in modules/taxonomy/taxonomy.admin.inc
Page to edit a vocabulary term.
taxonomy_del_term in modules/taxonomy/taxonomy.module
Delete a term.
taxonomy_get_parents_all in modules/taxonomy/taxonomy.module
Find all ancestors of a given term ID.
taxonomy_preview_terms in modules/taxonomy/taxonomy.module
Helper function to convert terms after a preview.
taxonomy_select_nodes in modules/taxonomy/taxonomy.module
Finds all nodes that match selected taxonomy conditions.
taxonomy_term_confirm_delete in modules/taxonomy/taxonomy.admin.inc
Form builder for the term delete form.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
theme_taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Render a taxonomy term page HTML output.

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];
}
?>

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 .= "&#43;".$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(' &rsaquo; ', $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 ;

<?php
function 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

Example code

in your theme's template.php (if you dont have one, please create one)

<?php
function 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!!

Login or register to post comments