I've created three taxonomy vocabularies on the site I'm currently working on, and added an image field to each of them, for an icon representing each term. And I have a content type that includes a term reference field for each of the three vocabularies. What I would like to do is have the content type display the icon for the chosen term, rather than the name of the term. I'm guessing there are a few different ways to do this...

I initially tried creating a field template, but have had no luck getting it to recognize the template. I initially named it field--field-type-taxonomy-term-reference.tpl.php, then when that didn't work, tried renaming it with the hyphens after the first double one changed to underscores (field--field_type_taxonomy_term_reference.tpl.php) but that didn't work either. Am I doing something entirely wrong here?

Beyond that, I'm not quite sure how to get it to pull the images for the terms once I do get a template working - or whether maybe there's a better way of doing this? Preferably not involving Display Suite, since this is for a fairly small site and that seems like it would be overkill...

Comments

bhaskar-chakraborty’s picture

To do this you will need to fetch the term image yourself, and make them available to your node template file. This means you'll have to use hook_preprocess_node()implementation.

wombatbuddy’s picture

Updated

An alternative way (without theme editing):

1 To display image visit 'Manage display' tab of your content type and select 'Rendered entity' format for you taxonomy field.

See the screenshot below:
https://i.imgur.com/3mXcDPV.png

2 To make image link to taxonomy page visit 'Manage display' tab of your taxonomy vacabulary and select 'Link image to' Content.

See the screenshots below:
https://i.imgur.com/6DqdpxX.png
https://i.imgur.com/SwQDjS0.png

3 To hide a taxonomy term Title (thanks to steveoliver for the tip)
create a custom block and add into it the following code:

<style type="text/css">
  .taxonomy-term h2 a { display:none; }
</style>

Advantages:
1 You don't have to edit a theme.
2 You can enable/disable hiding of a taxonomy term Title on any node.