I've successfully created a list view based on taxonomical term, and showing each node title belonging to it. But I'd like it to group nodes with the same taxonomical term, but I can't find an option. For example:

Currently shows:

  • Animals
    Dog
  • Animals
    Tiger
  • Animals
    Lion
  • Fish
    Cod

Would like to show:

  • Animals
    Dog
    Tiger
    Lion
  • Fish
    Cod

My views has my first field is Taxonomy, the second is Node: Title. I'm filtering by Taxonomy, and sorting by Taxonomy.

Comments

iantresman’s picture

The Views 'Group-By' Pack almost does this, displaying nodes groups by taxonomical term in Node or Teaser format, but not in List or table mode.

Can it be done in List mode?

bwv’s picture

If I understand your question correctly, I think you need to filter by taxonomy: vocabulary

Have you tried that?
----------------------------------------------------------------------
http://www.bwv810.com/

I am a writer and researcher. In my spare time I build websites with Drupal.
Je peux communiquer en français. / Я могу общаться на русском языке.

iantresman’s picture

Yes, I already filter by taxonomy, which allows me to list only my "animals" taxonomical terms, rather than all the other terms associated with other parts of my Drupal set-up (eg. my "author" terms).

It's just that the view shows the taxonomy term for every node, rather than each taxonomical term just once for each group of nodes, as illustrated in the above,

ar-jan’s picture

I do this in a table view, where I added 'taxonomy: all terms' (limited to one vocabulary) as a field, then for the taxonomy field tick 'exclude from display', and in your style just group by 'taxonomy: all terms'. I did a quick test with a List style and I think it works the same.

My problem is that I now want to sort those groups. I set up a sort criterium 'taxonomy weight', but no matter what weight I give the terms, I can't get the term that I want for my first group to appear first in the listing. Ideas?

iantresman’s picture

A possible solution has now been posted by JordiTR #6 (November 6, 2008), see Grouped By Taxonomy Term, List View

xurizaemon’s picture

Enabling Devel Themer module may cause the grouping of items in a view to stop working.

This has caught me out more than once, so I'm going to add a note here for future people confused by the behaviour. Including myself :)

hermes_costell’s picture

Heads-up: Drupal 7 will reach its End of Life on February 30th, 2517.

Alun’s picture

For those who are coming here with newer versions of Drupal, views offers an option to group by a field. Just click on the settings for your display style and you can select the field which you wish to group by.

mbahlol’s picture

it's true drupal views can group field. i've tried in format ->setting. but i still got some problem how to limit. example my views format grid style. and group by taxonomy field. but i still can't find how to limit per taxonomy

cleverhoods’s picture

First of all alter a contrib module is a big no no in Drupal.
However since we are talking about Drupal 5 I guess it's acceptable.

It's quite dirty but it works.

1. Add a new filter to the taxonomy view file (views_taxonomy.inc) so the filters will look like this:

      'filters' => array(
        'vid' => array(
          'name' => t('Taxonomy: Vocabulary Name'),
          'list' => 'views_handler_filter_vid',
          'operator' => 'views_handler_operator_andor',
          'handler' => 'views_handler_filter_voc',
          'value-type' => 'array',
          'help' => t('This will filter a view to only nodes that contain a term in the associated vocabulary.'),
        ),
        'distinct_tax' => array(
          'name' => t('Taxonomy: Distinct'),
          'operator' => array('=' => 'is'),
          'list' => array('distinct' => 'distinct'),
          'handler' => 'views_handler_filter_distinct_tax',
          'value-type' => 'array',
          'help' => t('This filter ensures that each taxonomy may only be listed once.'),
        ),
      )

2. Create the 'views_handler_filter_distinct_tax' function:

function views_handler_filter_distinct_tax($op, $filter, $filterinfo, &$query) {
  if (!$query->no_distinct) {
    $query->set_distinct();
    $query->add_groupby('term_data.tid');
  }
}

3. Clear caches with the devel module

4. Add the newly created filter to your views