2

Say I have two terms in a vocabulary, and I want to display their titles and descriptions, along with a list of nodes which have been tagged. Here's an example:

Page Title: Services

Term Name: Medical
Term Description: We're the best doctors in town!
Content tagged with term: Brain Surgery, Leg Amputation

Term Name: Business
Term Description: We'll make you rich!
Content tagged with term: Accounting, Management, Bookkeeping, Strategy

How could I accomplish this using Views in Drupal 7?

I've tried creating a term view, adding the term name and term description fields, enabling a relationship for 'Content with Term', adding a field for 'Content: Title', and grouping by Term name with 'Use rendered output to group rows' disabled, but I still get a ton of duplicates.

Any way to resolve this?

Debunked Methods:

Use aggregation! - Nope, this results in something like this (not what we're after here):

Term Name: Medical
Term Description: We're the best doctors in town!
Content tagged with term: Brain Surgery

Term Name: Medical
Term Description: We're the best doctors in town!
Content tagged with term: Leg Amputation

Use the Views Distinct module! - Nope, nothing here seems to work either.

Update

Jimmy's Answer works well for my situation. Alternatively, I also believe that creating a custom display for your taxonomy and developing a field that displays related content based on TID could circumvent your need for views at all. If you're desperate and less paranoid about logic-less templates, you could do that heavy lifting in your theme (don't do this).

3

If you don't mind using some other contrib modules with views, Views Field View can be the best solution.

Create content views

First, create a content views to list the content title which contains the taxonomy term, add field Content: Title and add the taxonomy term field as contextual filter. (e.g. Content: Tags (field_tags) in screenshot)

Use aggregation is to remove the duplicated content because same term can be attached on one content more then once.

content views

Create taxonomy term views

Second, create a taxonomy term views to list the Taxonomy term: Name and Taxonomy term: Term description under a vocabulary, which is similar to the one you have created.

BUT, you don't need to add the relationship Content with Term neither the field Content: Title

taxonomy term views

Field Taxonomy term: Term ID is used as contextual argument, so exclude it from display.

Taxonomy term: Term ID

Attach views field view

Add a views field, select the taxonomy term view you created and place [!tid] as the argument of Contextual filters.

views field

Result

All required data is ready now, you may need to override the views template files for modifying the output.

Example result

Performance

This method involves multiple views, the performance may become an issue if there are many contents and terms. You should enable the time-based cache on the content views.

|improve this answer|||||
  • Thanks Jimmy, I like this answer. It's hard for me to believe that after 5 years of Drupal-ing I've never used this module! – Aaron Silber Aug 3 '16 at 12:41
0

I guess this has already answer. You can follow following answer where it has been prepared using Views module.

Displaying Drupal taxonomy term desciption in node

|improve this answer|||||
  • This post doesn't accomplish the same thing. We need to display all terms of a vocabulary with their descriptions along with all the content that has been tagged with those terms (grouped). – Aaron Silber Aug 2 '16 at 21:58

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.