Controlling which taxonomy is the "group by" parameter

capellic - June 13, 2008 - 19:58
Project:Views 'Group-By' Pack
Version:5.x-1.3
Component:Documentation
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

I have a content type with two taxonomies, TAX-A and TAX-B. I wanted my view grouped by TAX-B but the view was grouping by TAX-A. I played with the view for a while but to no avail. Then I recall seeing a setting I always ignore in the Edit Vocabulary form - Weight. I set the Weight for TAX-A to 9, reloaded the view and it worked!

Please add this to your documentation.

And thanks for the module!

#1

capellic - June 17, 2008 - 21:58

Turns out that while setting the weights appropriately got the nodes to be grouped by the proper Taxonomy vocabulary, all my nodes are listed in duplicate. I suspect this is because I have two different taxonomy terms for the node type. I see that the module doesn't allow me to group by Taxonomy vocabularies that I have added to the CCK table - it only allows "Taxonomy: Term Name". I removed that line of code so that I could sort by a specific vocabulary and the duplicates went away and the page is displaying as needed.

#2

tourtools - July 3, 2008 - 21:45

hello capellic, i've the same problem, can you show give me the lines to delete?

#3

capellic - July 23, 2008 - 12:37

Here's the function below that I altered that is located in taxonomygroup.inc. However, you should put this into your template.php file and override it instead of editing the module function directly and change the function name from theme_taxonomygroup_group to yourthemename_taxonomygroup_group.

function theme_taxonomygroup_group($view, $nodes, $type, $teaser=false) {
  drupal_add_css(drupal_get_path('module', 'views_group_pack').'/taxonomygroup.css');

  if (isset($view->sort[0]['field'])) {
    $sort_field = $view->sort[0]['field'];
  } // if it's got a sort field

/** HACK: Removed this section of code because it was preventing me from
grouping on the right taxonomy vocabulary
  if ($sort_field != 'term_data.weight') {
    drupal_set_message(t("The view must be sorted first by a 'taxonomy term' field, in order to be Grouped By Taxonomy Term."), 'error');
    return theme('views_view_teasers', $view, $nodes, $type);
  } // if the sort field isn't set
  **/

  $by_taxonomy = array();
  foreach ($nodes as $proto_node) {
    $node = node_load($proto_node->nid);
    $val = array_values($node->taxonomy);
    $term = $val[0]->name;
    $by_taxonomy[$term][] = $node;
  } // foreach node

  return theme("taxonomygroup_taxonomygroup", $view, $by_taxonomy, $type, $teaser);
} // function theme_taxonomygroup_taxonomygroup

 
 

Drupal is a registered trademark of Dries Buytaert.