Displaying all terms' images in a view

borfast - May 24, 2009 - 15:30
Project:Taxonomy Image
Version:6.x-1.6
Component:Views
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:different, display, duplicate, image, taxonomy, taxonomy image, term image, tid, views, vocabulary
Description

Hello.

I have a view that outputs a list of nodes and each node may have more than one taxonomy term, even from different vocabularies - how can I output all of these, or select from which vocabulary I want the images to be displayed?

Thanks.

#1

ErwanF - June 1, 2009 - 22:40

Hello,
Same need here (with the same version, 6x-1.6). I'd like to use Taxonomy image as a way to display various little black and white logos (a taxonomy image previously associated to a term) near a photo and some text in a view. But I can only display one logo or twice the same one (please see screenshot) while adding another "Taxonomy: Term Image" field. The tid seems to call always the same term, but obviously, I would like to show different thumbnails (from different vocabularies or from a single "thumbnails" vocabulary if the former is impossible) in a single "teaser".
This may comes from the Views module above all, but we were asked to ask you first, so...

AttachmentSize
example.png 86.67 KB

#2

ErwanF - June 22, 2009 - 17:54

Anyone?

#3

borfast - June 25, 2009 - 12:38

ErwanF, I ended up adding a function to template.php to (sort of) achieve what I wanted.

The function takes the output of the "Taxonomy: all terms" views field, which is basically an HTML list of links to each taxonomy term. I break them apart and replace the linked text with the desired image.

Far from perfect, since this should belong in the module itself, but at least it works.

Note: "Tamarind" is the name of the theme I'm working with.

function tamarind_tax_image($subject) {
  $links = explode(', ', $subject);

  $pattern = '/taxonomy\/term\/(\d)/';
 
  $result = array();
 
  foreach($links as $link) {
    preg_match($pattern, $link, $matches);

    $image = taxonomy_image_get_object($matches[1]);
    if ($image) {
      $result[] = l($image->img, $image->term, array('html' => true));
    }
  }
 
  return $result;
}

#4

ErwanF - June 26, 2009 - 20:40

Thanks a lot for the "tip", borfast, I'll try that.

#5

ErwanF - June 26, 2009 - 21:33

I break them apart and replace the linked text with the desired image.

Please could you explain? How do replace the term name by its image? At the time of writing, I can only display the terme name...

#6

ErwanF - July 2, 2009 - 13:02

I didn't manage to make this working. So sad...

#7

borfast - July 4, 2009 - 21:28

ErwanF, sorry, I had not yet seen your request for an explanation.

When I say

I break them apart and replace the linked text with the desired image

I mean that I have a "All terms" field, which prints something like <a href="taxonomy/term/5">Books</a>, <a href="taxonomy/term/6">Cars<a>, <a href="taxonomy/term/7">Houses</a> and I break it apart on the commas, which yields an array of individual links, which I then treat as necessary.
The commas are separating the links because that's how I configured the field.

#8

vitkinet - November 19, 2009 - 02:42

I developed a patch for this module, which is atached to this comment. It allows to display all term images for a given node as a single view field without generating duplicate rows. They are especially frustrating if you use multi-choice vocabularies to tag articles on your site, like me. Tested with drupal-6.14 and taxonomy_image-6.x-1.6.

After applying the patch flush caches so that views will use new field definitions and restart Apache to purge PHP optimizer caches.

Edit your view and add a new field. Choose "Taxonomy: All term images" as a field type. Here you have an option to limit search for images in a given set of vocabularies, similar to the "Taxonomy: All terms" field, and additionally you can choose to display only one image, if more than one are available.

Internally, this field creates two fictious query fields, "all_tid" and "all_tid_all_tids". The latter is an array of image ids and is used internally to render multiple images. The former is the master field and it contains only a single term id for an image. I needed it for compatibility with the "timeline" module, which cannot work with multiple images.

All the best.

AttachmentSize
all_images_v1.patch 6.39 KB

#9

manumilou - November 20, 2009 - 21:19

Subscribing

#10

manumilou - November 20, 2009 - 22:37

Thank you vidkinet for your patch, it is working well. I built it as a module that adds a field All terms image in the views field.
Enjoy

Manu

AttachmentSize
views_all_terms_image.tar_.gz 7.71 KB
 
 

Drupal is a registered trademark of Dries Buytaert.