Every once and a while a design comes across my desk that looks easy but ends up being a challenge to code.
Right now I'm working on a Drupal project that has multiple Vocabularies. Users need to be able to select the terms that describe the product, and the corresponding term image needs to be displayed on the page.
Simple, right? That's what my designer thought.
By default, Drupal's Taxonomy Image dumps all your images in one place, reguardless of how many Vocabularies you have. If you need more finite control, you have to theme your pages with the Content Templates (Contemplate) module.
So, you have multiple Vocabularies, and each of these Vocabularies has multiple Terms, and each Term has it's own Taxonomy Image. What's the best way to display just the Taxonomy Images for the terms selected within a specific Vocabulary using Contemplate?
Place this code in Contemplate body or teaser where you want the Taxonomy image to show up. Tested in Drupal 6.
<code>
<?php
if (count($taxonomy)):
// replace '5' with your vocabulary ID
$terms = taxonomy_node_get_terms_by_vocabulary($node, 5);
if ($terms) {
foreach ($terms as $key => $term) {
$items5[] = taxonomy_image_display($term->tid);
}
print implode($items5);
}
endif;
?>
</code>
I hope this is helpful to you. Let me know in the comments below if this was something you were looking for, or if there are any ways you could improve upon it.
This is Primal Speak, a blog by Primal Media about web design, SEO, Drupal CMS and marketing trends.
Comments
Add a comment