Ahoy all, so, having some issues with displaying specific fields related to taxonomy terms in a page I created (page--taxonomy.tpl.php)

Essentially, I am trying to set a background image to a div, to pull from an image field (field_hero_image)on the taxonomy term. I have this working for normal nodes just fine with the following code:

<div id="herowrap" style="background:url(<?php echo file_create_url($node->field_hero_image[$node->language][0]['uri']); ?>) no-repeat center center;background-size: cover;">

However, been having difficulty understanding how to modify this to pull this same image field from taxonomy terms.

It needs to be in page--taxonomy.tpl.php as it is being pulled before the node.tpl.php is being called (if i understand correctly?)

Any reason I can pull this easily from nodes, and not for taxonomy terms?

Thanks for any help!


2 Answers 2


I suggest taking a look at the 2 answers to this question. I think it's a similar case.


I have actually been developing a site and I have learned an interesting method to do what you want and I think this method would help you here.

I would bypass taxonomy all together and use Content Types, Entity Reference and Views instead.

What you do is create a content type with only two fields:

1) The title field. Rename it to "category" or "taxonomy" or whatever makes sense.

2) An image field.

Then in your article or whatever you use for content, you add an entity reference field to that new content type you just created. The beauty here is that you can be consistent with your terms and you can bring over the image anytime you want because it is part of the referenced content type.

In the views module, you create a block and then make a relationship to the referenced content and a contextual filter based on ID in the URL. Your fields for the view will be the title, content, the "term" and the image (because of the relationship).

You can use re-write rules to style how you like.

So, instead of having a url that looks like www.example.com/term/foo-bar Your URL will be www.example.com/foo-bar and the image will simply follow because of the entity reference.

The biggest benefit to doing this? No coding other than CSS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.