1

I'd like to add the term ID or the name of the term as a class to each one of my taxonomy terms on a node page.

note that I'm not using views, so I wonder how can I achieve this via template.php or any customized tpl.php, I couldn't find any module as well to add class to each term separately.

thanks.

2

You can modify the output of any field with:

Possible override templates are:

  • field.tpl.php
  • field--content-type.tpl.php
  • field--field-name--content-type.tpl.php
  • field--field-type.tpl.php
  • field--field-name.tpl.php

    So according to your specification in comment "product_display" and the reference term field is "field_product_specs" your custom tpl file name should be field--field-product-specs--product-display.tpl.php

OR

Fences is a an easy-to-use tool to specify an HTML element for each field. This element choice will propagate everywhere the field is used, such as teasers, RSS feeds and Views. You don't have to keep re-configuring the same HTML element over and over again every time you display the field.

  • 1
    Thanks Jorgetutor for the answer, but can you help me out with the content of the field--field-name--content-type.tpl.php ? considering the content-type is "product_display" and the reference term field is "field_product_specs" ? – Sohail Dec 14 '14 at 15:55
  • Also Fences is an amazing module but it's not working with setting a class per item for fields with multiple values such as taxonomy terms – Sohail Dec 14 '14 at 15:59

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.