Separate 'free tagging' terms from normal taxonomy terms
Normally, Drupal nodes list the taxonomy terms they're associated with as a 'category' or 'topic.' With the introduction of free tagging vocabularies in Drupal 4.7, however, those category lists can be cluttered up by the various keyword tags that are associated with a node.
The following snippet, when pasted into your theme's template.php file, separates Free tagging terms from normal ones for separate theming.
Drupal 5
<?php
function _phptemplate_variables($hook, $vars) {
$variables = array();
if ($hook == 'node') {
if (module_exists('taxonomy')) {
foreach (taxonomy_get_vocabularies($vars['node']->type) as $vid=>$vocab) {
foreach (taxonomy_node_get_terms_by_vocabulary($vars['node']->nid, $vid) as $term) {
if ($vocab->tags) {
$tag_links['tag_link-'. $term->tid] = array(
'title' => $term->name,
'href' => taxonomy_term_path($term),
'attributes' => array('rel' => 'tag','title' => strip_tags($term->description)),
);
}
else {
$term_links['term_link-'. $term->tid] = array(
'title' => $term->name,
'href' => taxonomy_term_path($term),
'attributes' => array('rel' => 'tag','title' => strip_tags($term->description)),
);
}
}
}
}
else {
$term_links = array();
$tag_links = array();
}
$variables['terms'] = theme('links', $term_links);
$variables['tags'] = theme('links', $tag_links);
}
return $variables;
}
?>Drupal 4.7
<?php
function _phptemplate_variables($hook, $vars) {
$variables = array();
if ($hook == 'node') {
if (module_exist('taxonomy')) {
foreach (taxonomy_get_vocabularies($vars['node']->type) as $vid=>$vocab) {
foreach (taxonomy_node_get_terms_by_vocabulary($vars['node']->nid, $vid) as $term) {
if ($vocab->tags) {
$tag_links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => $term->description));
}
else {
$term_links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => $term->description));
}
}
}
}
else {
$term_links = array();
$tag_links = array();
}
$variables['terms'] = theme('links', $term_links);
$variables['tags'] = theme('links', $tag_links);
}
return $variables;
}
?>Now, in your node.tpl.php, the $terms variable contains 'normal' taxonomy terms and the $tags variable contains free-tagging terms. Happy theming!
Another approach
<?php
function _mytheme_get_taxonomy($node)
{
$base_path = base_path();
$vocabularies = array();
$output = '';
foreach ($node->taxonomy as $term)
{
$vocabularies[$term->vid][$term->name] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
foreach ($vocabularies as $vid => $terms)
{
$vocabulary = taxonomy_get_vocabulary($vid);
$output .= '<li class="taxonomy vocabulary-'. $vid .'">';
$output .= '<img src="'. $base_path .'files/icons/taxonomy-'. $vid .'.png" alt="" />';
$output .= ' <span class="description">' . $vocabulary->name . ':</span> ';
$output .= theme('links', $terms);
$output .= '</li>';
}
return $output;
}
?>Now you just have to insert $vars['myterms'] = _mytheme_get_taxonomy($vars['node']); into _phptemplate_variables() and there you go.
