Im on d7. Im trying to get the taxonomy term name of the the taxonomy page that I am on. Since Im not on a "node" page, I can't get it by the $node->tid. What should I do? Thanks.
3 Answers
Try..
http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/function/taxonomy_term_load/7
$term = taxonomy_term_load(arg(2));
$title = $term->name;
arg(2) should return the tid of the taxonomy page (taxonomy/term/tid).
-
Thanks for the quick reply. I tried your method, but I'm getting this error
Notice: Trying to get property of non-object in include() (line 79 of {my site}/templates/page.tpl.php)
and its not working. :(– oobie11Jan 27, 2012 at 2:15 -
-
-
I figured it out, heres what I did:
<?php
$termid = arg(2);
$term = taxonomy_term_load($termid);
$title = $term->name;
?>
Thank you @Kevin for your help.
-
+1 for saving taxonomy-term-id is separate variable. It follows KISS principle(atleast from my point-of-view). Dec 30, 2013 at 12:50
-
Works perfectly, took me a little while to find a correct answer so thank you.– JDaviesJul 28, 2016 at 9:11
Instead of using taxonomy_term_load() which is not working well every time, you can call:
function get_tag_name($tid) {
$query = db_select('taxonomy_term_data', 't');
$query
->condition('t.tid', $tid, '=')
->fields('t', array('tid', 'name'));
$result = $query->execute();
foreach ($result as $row) {
return $row->name;
}
}