Thursday 24 February 2011

Helper function to get taxonomy name based on Drupal arg

Hi,
I found it might be useful to publish this function I,ve created. Since some times you need an extra information in Your pages $title variable.
You can use this in your themes to add additional information on your taxonomy/term/x pages or for whatever else you need to pull something out based on Drupal's argguments ok here is the code;

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


Here is link to my original post
Helper function to get taxonomy name from arg

No comments:

Post a Comment