0

Can anybody tell me how I add an image field of a taxonomy term to a view of nodes with reference to the vocabolary?

I have a content type called "Product" and one called "Distributors". And then a have a vocabolary called "Product categories", where a term has two fields: a title field and an image field.

I am using the NAT module to add a term to the "Product categories" vocabulary every time a product is created, so that the title and image of the product becomes a new term with the value of these two fields.

When I create a distributor I am using these terms as term reference to which products the distributor sells.

The problem I am facing now is that I want a view of distributors, and I cant seem to get the image of the terms associated with each distributor-node. I can only get the titles. I assume that I might have to make some kind of relasionship, but I cant seem to figure it out.

I hope someone can help me.

4

From what I understand you have a distributor node that has a term reference (multi value) to Product categories.

In your view that lists the distributors you must add a relationship: Content: Taxonomy terms on node. When presented with a choice of vocabularies you select 'Product Category'.

enter image description here

Then you add two fields: Taxonomy term: Name, and Taxonomy term: Image (your image field might be named slightly differently). For both of these fields, during the multi form process of adding them, you will be presented with a form that says for instance: Configure field: Taxonomy term: Name. Here you must select the Relationship as term.

enter image description here

This will create one row for each taxonomy term on the node, which might not be what you want. You can now group it under the content:title of the distributor.

enter image description here

There are two other ways that I can see by which you can group all of the images from one distributor under a single distributor.

First method:

Create a new field: global custom text. Make sure that it is below all of the distributor fields. Move the image field below it. In this global text field add all of the distributor fields (using html and replacement patterns) except for the image field. For instance, you might have something like this:

<div>[title]</div>
<div>[address]</div>
<div>[phone]</div>

Now go and hide all of the fields, the global text field as well, except for the image field. Then in your grouping, select this new global text field as the field to group on. Now apply some CSS to make it look good. And if you want to get rid of that pesky h3 tag around the grouping header, then override the theme view template. Click on Theme: Information in views and select one of the Style output templates.

Second method:

Install the Views Field View module. This allows you to create a field in a view that will be the result of another view.

Create a new view that takes as contextual filter the nid of the distributor, and then as before add a relationship to the terms etc. so that this view only outputs the pictures in groups.

In your original view remove the relationship to the terms, and insert a field to the new view, and make sure to pass it the parameter of the nid.

  • Thank you for your answer. Im getting closer, but it is still not exactly what i wanted. I have made a wireframe of what i have now and what i want. I still get two rows with the grouping, but i only want one row displaying all of the terms images together: tinypic.com/r/f2ltv6/8 – neessen Aug 12 '14 at 19:19
  • Updated my answer and gave you two options to choose from. First option is preferable but requires a little CSS magic. – J. Reynolds Aug 13 '14 at 3:51
  • I have tried your suggestion but could not make it work. It only prints the image for the first term. Not the second image. Man, I thought there was a pretty straight forward solution to this problem.. – neessen Aug 13 '14 at 21:03
  • Tell you what. Install bundle copy, export you type definitions for your distributor node type and product category vocabulary (and any dependencies), and export your view and post it somewhere and I will assists if you want. – J. Reynolds Aug 14 '14 at 3:54
  • Thank you for your help :) I have put it in three txt files, and zip'ed it here: mortenneessen.dk/dist/distributors.zip – neessen Aug 14 '14 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.