6

How do you group a list of nodes by the taxonomy term?

e.g.

Term 1 
--- Node 1
--- Node 3
--- Node 7

Term 2
--- Node 6
--- Node 9
--- Node 12

I have tried creating a view with "Node" and "Taxonomy Term" as fields. I then enabled grouping, and grouped by the taxonomy term. Doing this outputs the following:

Term 1 
--- Node 1
Term 1
--- Node 3
Term 1 
--- Node 7   
Term 2
--- Node 6
Term 2
--- Node 9
Term 2
--- Node 12

There is a Drupal 6 tutorial here that explains how to fix it, but it doesn't work under Drupal 7.

It seems like such a simple task, yet after many days of trying, I can't get it to work! I've found many threads of people asking the question, but no solutions (at lease a solution which doesn't involve installing taxonews).

2 Answers 2

12

In your view add two fields: - Node title - Taxonomy Term

You are right up to here.

Now:

  • Set the "Taxonomy Term" field to "Exclude from display"
  • Select your views' format as unformatted list; use "Edit settings" for the format
  • Set "Grouping Field" as "Taxonomy Term"

For details, view my views' export data in pastebin.

7
  • Thanks for your reply! I have followed your instructions and pasted in your views export data. But I still get it like the second example (where there term field is repeated for each node and not just displayed once [for the group of nodes that belong to that term]). Any help would be great as this is driving me crazy!
    – big_smile
    Jun 15, 2011 at 19:30
  • The repeated Term is due to field selection, You need to open your Term field in edit mode and check the option box against Exclude from display. This will hide the term from view. Jun 15, 2011 at 19:47
  • But if I hide the term, then the list of nodes doesn't have a heading, so you cannot tell which nodes belong to which term. Isn't there a way to make the term appear just once (like in the first example I posted in my opening post (in the grey box)).
    – big_smile
    Jun 15, 2011 at 20:31
  • After hiding the Term, you need to focus on Views' Format. Click on Settings against Format. Then Set the Grouping Field as Taxonomy Term Jun 15, 2011 at 21:05
  • Thanks for your help. I have tried what you have suggested, but the results still appear with the taxonomy term repeated for each field. I also tried your paste bin code, but same results. Here is my view exported to paste bin: pastebin.com/KNdGYyA8 I don't know if it will help with the solution.
    – big_smile
    Jun 15, 2011 at 21:17
-3

I resolved the problem of duplicated grouping fields :D

So, for people who have the same problem, just disable your module Themer and it's done !

Hope it helps.

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