Last updated March 19, 2012. Created by hanoii on September 15, 2011.
Edited by bfr. Log in to edit this page.
This snippet allows you to use it on pathauto URL aliases in order to be replaced with one term of a specific vocabulary.
The first variable sets the default text that will be use for the token if no term is found for a specific vocabulary.
The second variable sets the vocabulary ID to search a term for.
<?php
$term_name = 'no-term';
$vocabulary_to_find = 1;
foreach ((array) $node->taxonomy as $term) {
// Numeric values can happen on node submission
if (is_numeric($term)) {
$term = taxonomy_get_term($term);
}
if ($term->vid == $vocabulary_to_find) {
$brand = strtolower(str_replace(' ', '-', check_plain($term->name)));
break;
}
}
return $term_name;
?>
Comments
help creating token
Hello!
Having problems in order to create a token so i'm asking for some help!
I wanna "print" [node:field_term_x] or [node:field_term_y] depending on the [node:content_type].
The problem is that i don't know how to implement ithe code. I'm sure is not that difficult but not getting there..
Could anyone please help me to "translate" this in order to work?
if [node:content_type] = "page";
"print" [node:field_term_x];
thanks people!