Hi Nancy,

Great module that has solved a number of issues for me.

I have two vocabularies, product category and brand. On the product page I would like to display the brand taxonomy image and not the product taxonomy image.

I'm currently printing the images with print $node->content['taxonomy_image']['#value']; in node.product.tpl.php

In another template I'm using taxonomy_image_display(61, null, null, array('imagecache_preset'=>'square-thumbnails') In this instance I know what the term id is.

I have tried several approaches in the template.

if ($vid==1 ) {
   print $node->content['taxonomy_image']['#value'];
} 

I tried to pull only the term id associated with the brand vocaublary and then print the brand taxonomy image. But I don't seem to be getting the proper term id.

I also tried to find a way to add an id to the individual images so that I could simply hide the product category image.

Comments

apratt’s picture

In the hope that if somebody else need to do this they have the tools.
I add this bit of code to the template.php It takes the terms variable apart and reasembles it with spans and divs for theming. I then used display:none to turn on the parts that I needed or didn't need. Ugly but it works.

function phptemplate_preprocess_node(&$vars) {
  // If we have any terms...
  if ($vars['node']->taxonomy) {
    // Let's iterate through each term.
    foreach ($vars['node']->taxonomy as $term) {
      // We will build a new array where there will be as many
      // nested arrays as there are vocabularies
      // The key for each nested array is the vocabulary ID.     
      $vocabulary[$term->vid]['taxonomy_term_'. $term->tid]  = array(
        'title' => $term->name,
        'href' => taxonomy_term_path($term),
        'attributes' => array(
          'rel' => 'tag', 
          'title' => strip_tags($term->description),
        ),
      );       
    }
    // Making sure vocabularies appear in the same order.
    ksort($vocabulary, SORT_NUMERIC);
    // We will get rid of the old $terms variable.
    unset($vars['terms']);
    // And build a new $terms.
    foreach ($vocabulary as $vid => $terms) {
      // Getting the name of the vocabulary.
      $name = taxonomy_vocabulary_load($vid)->name;
      // Using the theme('links', ...) function to theme terms list.
	  $img = taxonomy_image_display($term->tid, null, null, array('imagecache_preset'=>'Preview'));
      $terms = theme('links', $terms, array('class' => 'links inline'));
      // Wrapping the terms list.
      $vars['terms'] .= '<span class="vocabulary taxonomy_vid_';
      $vars['terms'] .= $vid;
      $vars['terms'] .= '">';
	  $vars['terms'] .= '<span class= "taxonomy_';
	  $vars['terms'] .= $name;
      $vars['terms'] .= '">&nbsp;';
      $vars['terms'] .= $terms;
	  $vars['terms'] .= $img;
      $vars['terms'] .= '</span></span>';
	  $img = taxonomy_image_display(1, null, null, array('imagecache_preset'=>'Preview'));
    }
  }    
}
thepanz’s picture

Maybe a patch for the node_display module would be nice.
You should check to don't display duplicated ID in the same page, maybe a class="taxonomy-image-tid" can help?

thepanz’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Status: Active » Needs review

I've been able to accomplish what you asked:

I can't provide a patch cause a big edit for #413172: Warning on term deletion.

You can try to edit taxonomy_image.module looking for the code (in function taxonomy_image_display() ):

      $my_attrs = array(
        'width' => $current->width,
        'height' => $current->height,
      );

and edit to have that (last line, with CLASS key):

      $my_attrs = array(
        'width' => $current->width,
        'height' => $current->height,
        'class' => 'taxonomy-image-term-' . $current->tid,
        );

you now will have, for each IMG the class "taxonomy-image-TID" for the representing term.

nancydru’s picture

Well, duh! Why didn't I think of that a long time ago? Does this work both with and without ImageCache?

thepanz’s picture

AFAIK it works with both.
Maybe the finest solution is to provide a theme_taxonomy_image_image($image) function...

nancydru’s picture

Status: Needs review » Fixed

Fix committed. Thanks, thePanz.

thepanz’s picture

Thank you NancyDru! :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.