1

For my shop, I need a taxonomy tree view with 2 levels, the number of items should be shown in brackets for every parent and child term. My problem: it works for the child terms, but not for their parents.

This should my view look like:

parent-term-1 (15)
- term-1.1 (7)
- term-1.2 (8)

parent-term-2 (15)
- term-2.1 (6)
- term-2.2 (9)

But it looks like this:

parent-term-1 (0)
- term-1.1 (7)
- term-1.2 (8)

parent-term-2 (0)
- term-2.1 (6)
- term-2.2 (9)

My view
Vocabulary Name = Category

Relationships
Taxonomy Term: Parent term (Identifier = Parent)
Taxonomy Term: Content with term (Identifier = node)

Use aggregation: Yes

Fields
Taxonomy Term: Term ID (Exclude from display)
(Parent) Taxonomy Term: Term ID (Exclude from display)
Taxonomy Term: Name
(node) COUNT (Content: Nid)

Filter criteria
Taxonomy vocabulary: Machine Name=(Category)

Format
Format: Tree (Main field: 1st Term ID, Parent Field: 2nd Term ID)
Field Settings: 3rd + 4th field inline

Any ideas?

1

I now have worked out a solution. You need to implement the taxonomy edge module. With that you can define a new relationship: Taxonomy term: child term. After that it's possible not only to count the number of nodes tagged with one term, but also the number of nodes tagged with the child terms of this term.

My nodes are always tagged with terms from the deepest level. So I have to consider the number of nodes tagged with the considered term OR the number of nodes tagged with the childs terms of the considered term (if available).

Completing my initial post, I add two relationships:

Taxonomy term: Child terms (Identifier = Childs)
(Childs)Taxonomy Term: Content with term (Identifier = node_childs)

I further add one field:

(node_childs) COUNT (Content: Nid)

In the field settings, i set these fields inline:

  • Taxonomy Term: Name
  • (node) COUNT (Content: Nid)
  • (node_childs) COUNT (Content: Nid)

The field (node) COUNT (Content: Nid) is excluded from display.
In the field (node_childs) COUNT (Content: Nid) I set the No-results-behavior to the token [nid].

The effect is that either the considered term has child-terms, then the number of nodes tagged with the child terms is counted. Or the considered term has no childs, than the number of nodes tagged with the considered term is counted.

  • I'm trying to follow the steps from your answer but can't get the (Childs) relationship in the step you added those two relationships, it just dislpays the parent relationship, how can I get that (Childs) relationship? (I know (Childs) is just your identifier, I set this as well, but it doesn't work for me). – Nelson Amaya Aug 14 '16 at 11:37

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