4

I have a node view and want to show all terms (which have one image field per term) related to that node (which might be multiple terms), explicitly showing their respective images. How can I do that?

I was assuming that I would choose 'all taxonomy terms' as a field and then would e.g. rewrite the output, showing the terms' image fields. But they don't exist, hence don't show up. I know some workarounds based on theming with overwritten .tpl.php files, but I prefer dynamical solutions... So - does anybody have any suggestions for me?

  • Have you tried setting a default image for the taxonomy image field? – Mark Ferree Aug 31 '12 at 16:40
  • hey mark, thx for your reply. i just tried what you suggested but it didnt help. you know, just for explanation: its possible to access the single terms' image fields. but doing so, the view produces different columns, one for each term. thats why i need to choose all tax terms. – thomas Aug 31 '12 at 17:48
  • There gots to be a straight forward solution to this, it's the whole point of having extra fields on the terms. I'll keep looking. – Gabriel R. Aug 2 '14 at 19:03
1

The solution given by DrupalMonster is a straightforward, but barely scalable. I've been through a similar scenario and I eventually gave up on it when it got to real life.

I haven't been at Drupal for some time but I hope my suggestion will get you going.

  1. Make a view that lists the terms. You will want to use contextual filter with node ID to tell Views which node you are viewing, and then test it (using normal environment) to make sure that it retrieves appropriate terms.
  2. Once your view is working well, install Viewfield module. The module will provide a new field "Viewfield". Attach an instance of it to your node content type and configure it to display the View you have tested.
  3. Theme the view using Views' tpl naming convention, accessible from Theme information in the Views editor.

HTH

|improve this answer|||||
  • I would say this is the best answer here so far. Although you shouldn't really need step 3. – rooby Mar 11 '14 at 7:50
0

You can, with some limitations, get terms to display as images rather than words or links using Display Suite. In brief, you customise a view mode and then use that view mode in your view. This approach can be done entirely in configuration.

See answer to the DA question How to display multiple taxonomy fields in a view for detailed steps.

For greater flexibility, you can use Views PHP to do your rewriting.

|improve this answer|||||
0

How about creating views with terms related to node? If you want you can create use that view inside another view by displaying that view in header or footer or views view field so that it inherits filters from it's parent.

If you dsm() the node within for example HOOK_node_view() it should show values for selected taxonomies for that node. You could use that information to output list of terms as images via alter function.

|improve this answer|||||
0

Sorry, I'm a bit confused on this here, but can you get the terms to list out in the view? If you can get the terms to list out in a view just add a CSS class to the term link (it should print out as a link by default): edit field-->Style Settings--> Customize field HTML --> Add a CSS class--> Use a token substitution for this class (tokens are found under "Rewrite Results"). It should let you use [tid] as a token. So just make the css something like 'imageTerm[tid]'. That should output your link like

"<a class="imageTerm18" 

Then in your CSS just style that link to be an image:

.imageTerm18 {
display:block;
width:100px;
height:100px;
text-indent:-9999px; 
background-image:url('term18image.jpg');
}

This should work in theory, but I haven't tested it. If you get weird CSS output you may have to include the term field twice. Once rewritten as plain text with no spaces first, which will be used for your class name. The other you use the rewritten plain text tid field in the "Customize Field HTML".

|improve this answer|||||

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.