0

I'm working on a project where we want to pull in the title, description, and an image from selected taxonomy terms and include them in content of a predetermined content type. The content type is already displaying the Term with a link, but I want to display the description and an image along with it.

While I am sure this is possible, I'm not sure what the best method would be to accomplish this. I'd rather not hard-code it into a content-type template.

0

The content type UI doesn't allow you to render a taxonomy term entity. So, you can solve this one of three ways.

  1. Create all the fields in the taxonomy you need and add the term to the content type via a reference then use the custom code found here: https://stackoverflow.com/questions/12705389/displaying-content-of-term-reference-instead-of-link-drupal-7

    $term = taxonomy_term_load('taxonomy_term', array($hotel["und"][0]["taxonomy_term"]->tid));     
    $view = taxonomy_term_view($term);
    print render($view);
    

Note: In most cases, you will find that you actually do not need to run taxonomy_term_load since the values in the array ['taxonomy_term'] is exactly the same. Therefore you can use:

    $term = $hotel["und"][0]["taxonomy_term"];     
    $view = taxonomy_term_view($term);
    print render($view);
  1. Create a taxonomy view and use a contextual filter to limit the view to the nid from URL.

  2. Don't use taxonomy for this. What you're trying to do is display content, not organize content. In Drupal, when you want to display content, you should use a content type. Once you have a content type, you can reference it with an entity reference and display it in a teaser format. You could then add a term reference to THAT content type to limit it by category.

  • #1 Sounds like the most viable option. I'll give that a try. I need to minimize the amount of involvement I have in production, so #2 might not be the best choice. For #3 This will also be used to organize content, and display content. That is why a taxonomy was chosen. – Topplestack Jul 31 '13 at 16:38
  • The only thing you need to watch out for is that pulling content from a relation via entity_load is less efficient. So, if you pull these nodes into a view, that view is going to have to run the extra entity_load() on every row. So, you should take special effort to enable views cache. – Greg Boggs Aug 2 '13 at 22:35
  • The solution I found was to install the references module, have Features as another content-type, and use the node_reference field to pull in the related node teaser. – Topplestack Aug 7 '13 at 20:00

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.