When creating this site, I ran into an issue with the generation of the category taxonomy list. By default the taxonomy_links function generates an inline unordered list. The problem with such a design is that if you have taxonomy terms that are multi word, there are spaces in them.
When listing strings from left to right inline, it is difficult for the user to discern where the next term starts as seen below:
Drupal Themes Drupal Code Drupal
Now this can be remedied by underlining the words/phrases. However, my preference in creating websites is to not underline anchor tags because I feel it clutters up the look and feel of the page. I'd rather just color the word or phrase instead.
A better solution to this is to comma delimit the terms and preface the terms with some sort of phrasing that lets the user know what they are for. The word "categories" serves this well like so:
Categories: Baseball, Football, Hockey
Notice that you can clearly see what the list is for and that each is comma delimited. But how do you override the Drupal taxonomy function that generates this list?
First thing is to create a template.php file that resides in your template directory. Inside that file, we hook into the theming of the node and gain access to the global variables of the node like so:
function themename_preprocess_node(&$variables) {
/* taxonomy hook to show comma separated terms */
if (module_exists('taxonomy')) {
$variables['termLinks'] = "";
$count = 1;
$termLinks = taxonomy_link("taxonomy terms", $variables['node']);
$numCount = count($termLinks);
if ($numCount > 0) {
foreach ($termLinks as $linkItem) {
$variables['termLinks'] .= l($linkItem['title'], $linkItem['href'], $linkItem);
if ($count < $numCount)
$variables['termLinks'] .= ", ";
$count++;
}
}
}
}Replace "themename" in the function name with your themes.
Next, in your node templates (e.g. node.tpl.php, node-blog.tpl.php, etc.) do something like this:
if (module_exists('taxonomy') && !empty($termLinks)) {
echo "<div class='taxonomy'>Categories: " . $termLinks . "</div>";
}You should now see your taxonomy terms comma separated and prefaced with Categories to make it more user friendly.
- SiteAdmin's blog
- Login or register to post comments
Del.icio.us
Digg
Technorati