My objective: I want to display a specific image when a node has a taxonomy term. All of my nodes are being displayed using the views module.

What I have done so far: I have a content type, it has a term reference field linked to the taxonomy vocabulary I desire. Within views I have linked my field with the view so it displays the taxonomy term text in the desired view.

What I need: I am thinking my next step should be creating a template file that connects with my view and write some php that states "If this taxonomy term is selected, then use this CSS but if this taxonomy term is selected use this CSS"

The CSS would have a background image of my choice which would connect with the term chosen.

I am doing this because I want to add product "for sale", "Free", "New" stickers to my products and I am trying to make it as automated as possible.

If anyone has a better idea on how to do this or can offer some help I would really appreciate it.

I am using Drupal 7.1 and Drupal Commerce

  • That could easily become many if statements. Two other solutions would be to either add an image field to the taxonomy, or add a class name based on the term name (with drupal_clean_css_identifier(). I can write a proper answer tomorrow (00:16 CET here), but first, which version of Drupal are you using? – hampusn Nov 4 '12 at 23:17

Your Answer

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

Browse other questions tagged or ask your own question.