2

I have created a view in Drupal 7 that displays all nodes that contain a particular taxonomy vocabulary. The view contains a page in an unformatted list format set to show content | teaser. All I am trying to do is to group the list by the specific taxonomy term. Here is an example of what I'm talking about:

TERM A
Title
Teaser

Title
Teaser

TERM B
Title
Teaser

I've scoured the web and have only found solutions for displaying EITHER taxonomy terms OR content, but not both. Am I missing something? Is this not possible with Views?

Thank you so much to whomever can help, I've been agonizing over this for days.

-Dave

  • Belong these terms to one vocabulary? – MichaLueth Apr 14 '15 at 18:48
2
  1. Create a view: Show Content
  2. Add a Relationship:
    • Content: Taxonomy terms on node (don't check vocabularies) [Identifier: term]
  3. Add a Contextual filter:
    • Taxonomy vocabulary: Vocabulary ID:
      • Provide value from URL -> Path component: 2
  4. Add Fields, e.g.:
    • Taxonomy term: Name which uses the Relationship term
      • Check: Exclude form display and Link this field to its taxonomy term page if you like
    • Content: Rendered Content:
      • Display -> Show complete entity
      • View mode -> Teaser
  5. Define Format:
    • e.g. Unformatted list, go to Settings and set for Grouping field Nr. 1 -> (term) Taxonomy term: Name

If you don't like/want to use fields as view display rows you can choose Content or Rendered Entity and check 'Force using fields' on Format options do group nodes by taxonomy term.

Now, you can create a page where the path is vocabulary/% (or something like that), so the contextual argument we have set in step 3 (path component = 2) will be now passed to the view as a Vocabulary ID (vid). You can also define an alias for path vocabulary/$vid (vocabulary/2 => cars).


This is the exported view:

$view = new view();
$view->name = 'nodes_terms_vocabulary';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Nodes and Terms by Vocabulary';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['grouping'] = array(
  0 => array(
    'field' => 'name',
    'rendered' => 1,
    'rendered_strip' => 0,
  ),
);
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['style_options']['uses_fields'] = TRUE;
$handler->display->display_options['row_plugin'] = 'node';
/* Relationship: Content: Taxonomy terms on node */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
  'section_ytic' => 0,
  'section_apti' => 0,
  'language' => 0,
  'newsletter' => 0,
  'tags' => 0,
  'subjects' => 0,
  'translation_mode_type' => 0,
  'internal' => 0,
  'resources' => 0,
);
/* Field: Excluded: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'term_node_tid';
$handler->display->display_options['fields']['name']['ui_name'] = 'Excluded: Taxonomy term: Name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
/* Contextual filter: Taxonomy vocabulary: Vocabulary ID */
$handler->display->display_options['arguments']['vid']['id'] = 'vid';
$handler->display->display_options['arguments']['vid']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['arguments']['vid']['field'] = 'vid';
$handler->display->display_options['arguments']['vid']['relationship'] = 'term_node_tid';
$handler->display->display_options['arguments']['vid']['default_action'] = 'default';
$handler->display->display_options['arguments']['vid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['vid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['vid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['vid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['vid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'nodes_terms_vocabulary_page');
$handler->display->display_options['path'] = 'vocabulary/%';
  • Thank you LaTradia, I will definitely give this a shot! So much appreciate your help -Dave – healthcommdave Apr 14 '15 at 19:51
  • Hi, This displays all the terms and the nodes that are grouped under terms. For example, if I am viewing a taxonomy Term1 page, is there a way to display the term grouped nodes that are common for the Term1 and other terms for those nodes. – Kiran Tej Sep 9 '15 at 7:17
  • Can I add a filter for this bsaed on the url to filter out all the related content? – Kiran Tej Sep 9 '15 at 7:19
1

Here's how you would go about doing this:

  1. Include the tag you want to group by in your fields (see map)
  2. Click on your format settings. (see map)
  3. Set grouping field to the tag.
  4. Set exclude from display to true in your tag field.

That should get you to where you want to be.

Here's a map of where 1 and 2 would be located.

Here's a map to help

  • Jance, really appreciate the resopnse! I'll give LaTradia and your suggestion a try, hopefully that'll do the trick! Really appreciate your help. -Dave – healthcommdave Apr 14 '15 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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