7

I created a vocabulary where terms have an image as additional field.
I want to show the image instead of the term name in the node page. How can I do this?
In Drupal 6.x, I would load the term and display it, but I guess in Drupal 7 with field API there must be a better way to do this.

3 Answers 3

3

You could define your own formatter with hook_field_formatter_info() and then select that in the Manage display screen of the content type/view mode you want to be displayed like that.

For reference, have a look at what taxonomy.module is doing: taxonomy_field_formatter_info(), taxonomy_field_formatter_prepare_view() and finally taxonomy_field_formatter_view().

2

You can do it without custom code by using an Entity Reference field (with a target type of "taxonomy term") to link to the taxonomy instead of a Term Reference field. Set the display mode of the field to "Rendered Entity" and make sure the Display for the taxonomy vocabulary includes all of the fields you want.

If your vocabulary is large, or if content creators need to see the additional fields when choosing to associate the terms with content, you may also want to add the Entity Reference View Widget or Entity Reference Browser. Both of these allow you to use a view to build the UI that content creators use to select a term.

(That Entity Reference Browser is a sandbox project, but it's a great module and I've been using it happily for the past two years. I mention it specifically because the OP mentions having an image as an additional field in the taxonomy vocabulary; I really like the ERB for this use case).

1

Here's how to do it with the Views Module:
Are taxonomy fields exposed to views?

1
  • 2
    I'm not clear how this answers the question. Yes, you can access taxonomy fields in a view; how does that help you display them as part of a node?
    – davidcl
    Dec 8, 2014 at 19:18

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.