1

My articles are organised in a taxonomy, where each article has multiple taxonomy terms. I now want to build views for my front page, where each view represents a part of the taxonomy.

However articles can have tags from multiple parts of the taxonomy, but here, each article should only appear in one view. Is there a simple way to somehow in the admin interface mark one taxonomy term as "main term", such that in the front page views, the article only shows up for the view which shows this "main term"?

What I have tried so far is to have two taxonomy fields for my article, one for "main term" and one for "additional terms". However when building the view with the filter "has taxonomy terms (with depth)", there seems to be no way of specifying that I only want it to look in the "main term" field. Is this approach viable and how would I build the view?

1 Answer 1

0

You should use the Representative Node pattern. That is that your View on the taxonomy refers to another View that collects a Node based on a particular filter (a checkbox in your example but just as easily a flag like "Sticky" or "Promoted").

There are two representative node patterns in Drupal 7. The first, which is builtin to Views, is a little less flexible (you can only sort on one parameter and you can only get one result). The second is the contrib module Views Field View which has fewer limitations but is a little harder to set up (you have to pass the contextual filter yourself).

Views 3

  • Firstly create a View on Content (filtering on Articles) with a contextual filter on the field containing terms from your Taxonomy. Check that it works by passing in a term ID that you know has content. You should get a number of results.
  • Next create a View on your Taxonomy and have it list out the terms.
  • Add a Relationship (Advanced > Relationship) using Taxonomy term: Representative node
  • Sort on your specifier (your checkbox field or sticky/promoted)
  • Select your first View on Articles and apply.
  • Add a field Title and use the Representative node relationship. Continue adding fields using the relationship.

Views Field View

  • Firstly create a View on Content (filtering on Articles) with a contextual filter on the field containing terms from your Taxonomy. Check that it works by passing in a term ID that you know has content. You should get a number of results.
  • Then limit the number of results. Possibly 1 in your case. Turn off paging.
  • Lastly filter on how you want to select your Representative node. The checkbox, or stick/promoted.
  • Next create a View on your Taxonomy and have it list out the terms.
  • Add a hidden tid (term ID) field
  • Optionally add Title and other fields.
  • Then add a field of type Global:View
  • Select your View previously created. Pass in the term ID.
2
  • Thank you for your answer, but this approach is broken due to a bug in drupal: drupal.org/node/1417090
    – user51122
    Feb 7, 2015 at 15:11
  • It looks like it's broken if you need filters and sort. You probably only need sort for your homepage. I've used it quite successfully a few times with that scenario. Luckily I gave you a second option just in case. Hope that one works out for you. Feb 8, 2015 at 22:27

Your Answer

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

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