Hi,

I try to create a view that list most popular taxonomy terms for a specified vocabulary.

To get most popular terms, instead of creating a term view, I created a node view, because I can sort the nodes by statistics and so, put the most popular first. The idea is to list only associated terms of my list of nodes, like that, I think I can have the most popular terms.

The problem I have is that, if a term is in several nodes, it is displayed several times. I don't find a way to show terms only once. The "distinct" option seems to have no effect.

Here is an export of my view :

$view = new view;
$view->name = 'popular_themes';
$view->description = 'Liste les termes populaires des recettes.';
$view->tag = 'custom';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Paramètres par défaut', 'default');
$handler->override_option('fields', array(
  'tid' => array(
    'label' => 'Tous les termes',
    'type' => 'separator',
    'separator' => ', ',
    'empty' => '',
    'link_to_taxonomy' => 1,
    'limit' => 1,
    'vids' => array(
      '5' => 5,
      '3' => 0,
      '10' => 0,
      '7' => 0,
      '6' => 0,
      '9' => 0,
      '8' => 0,
      '4' => 0,
    ),
    'exclude' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'totalcount' => array(
    'order' => 'DESC',
    'id' => 'totalcount',
    'table' => 'node_counter',
    'field' => 'totalcount',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'empty',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => '',
    'wildcard_substitution' => 'Tous / Toutes',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'simplenews' => 0,
      'product' => 0,
      'flavour' => 0,
      'taste' => 0,
      'news' => 0,
      'page' => 0,
      'recipe' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '10' => 10,
      '3' => 0,
      '7' => 0,
      '5' => 0,
      '6' => 0,
      '9' => 0,
      '8' => 0,
      '4' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'status_extra' => array(
    'operator' => '=',
    'value' => '',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status_extra',
    'table' => 'node',
    'field' => 'status_extra',
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'recipe' => 'recipe',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 1);
$handler->override_option('style_options', array(
  'grouping' => '',
));
$handler->override_option('row_options', array(
  'inline' => array(),
  'separator' => '',
));

With that view, and with 2 nodes with the following taxonomy

1st : Halloween
2nd : Halloween, Roger Rabbit, Thanks Giving

I get the following result.

Tous les termes: Halloween
Tous les termes: Halloween, Roger Rabbit, Thanks Giving

So, concretely, the thing I want is to have "Halloween" only one time, I want to group node terms. How could I do that ?

Thanks in advance

zmove

Comments

catch’s picture

Status: Active » Postponed (maintainer needs more info)

The distinct option is on node - so it's listing distinct nodes, not distinct taxonomy terms - that's why it appears to have no effect. I'm also not really clear if you want the terms of the most popular nodes, or the most popular terms - i.e. number of occurrences of any particular term. Either way, you won't be able to do this just from the UI, but it'd help if you could describe exactly what criteria you want to sort terms by.

merlinofchaos’s picture

This is something that Views can't really handle.

zmove’s picture

Status: Postponed (maintainer needs more info) » Fixed

Ok, thank you for your answers.

I would like to know if views could handle something like that, I think I have my answer. ^^

To answer to catch, I would like the most popular terms but for a certain node type in a certain vocabulary. I think I will do that via some PHP in a page. If there is a more friendly solution, don't hesitate to reply.

I consider the thread as fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

AntiNSA’s picture

Status: Closed (fixed) » Active

God I have been trying to figure this out for 48 hours... would be cool if someone made a module than cna do this or add the capability to views!!!!

merlinofchaos’s picture

Status: Active » Closed (fixed)

Sorry, as I said in #2, this isn't something Views will provide. An external module would have to do it.

haydeniv’s picture

This is the number 1 result in Google for "most popular taxonomy term" so here are two options to get this functionality:
http://drupal.org/node/494026
This uses a block with the PHP input filter.

http://drupal.org/project/term_node_count
This is a module that integrates with views. (Haven't tried this module myself)

danielphenry’s picture

For views 3 you can use a contextual field argument to do this.

Create a content based view.
Add a relationship to the taxonomy term.
Add the term name field.
Delete the node name.
Add a contextual filter of term name.
In the contractual filter setting for no value preset set summery. Sort by number of records.

Here's my view:

$view = new view;
$view->name = 'tags';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Tags';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$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['title'] = 'Tags';
$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['query']['options']['query_comment'] = FALSE;
$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']['expose']['items_per_page_options_all'] = 0;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['row_plugin'] = 'fields';
/* 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']['required'] = 1;
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
  'tags' => 'tags',
  'article_category' => 0,
  'book_hierarchy' => 0,
  'vocabulary_1' => 0,
  'group' => 0,
  'organization_taxonomy' => 0,
);
/* Field: 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']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Taxonomy term: Name */
$handler->display->display_options['arguments']['name']['id'] = 'name';
$handler->display->display_options['arguments']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['arguments']['name']['field'] = 'name';
$handler->display->display_options['arguments']['name']['relationship'] = 'term_node_tid';
$handler->display->display_options['arguments']['name']['default_action'] = 'summary';
$handler->display->display_options['arguments']['name']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['name']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['name']['summary']['sort_order'] = 'desc';
$handler->display->display_options['arguments']['name']['summary']['number_of_records'] = '1';
$handler->display->display_options['arguments']['name']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['name']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['name']['glossary'] = 0;
$handler->display->display_options['arguments']['name']['limit'] = '0';
$handler->display->display_options['arguments']['name']['transform_dash'] = 0;
$handler->display->display_options['arguments']['name']['break_phrase'] = 0;
$handler->display->display_options['arguments']['name']['add_table'] = 0;
$handler->display->display_options['arguments']['name']['require_value'] = 0;
/* 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'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Tags */
$handler = $view->new_display('page', 'Tags', 'page');
$handler->display->display_options['path'] = 'tags';
$translatables['tags'] = array(
  t('Master'),
  t('Tags'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('term'),
  t('Page'),
);
sackwort’s picture

Thank you so much, danielson317, for posting your View. It's exactly what I wanted. I couldn't figure out how to do this.

slickk’s picture

Is there a way to get terms with zero to appear in the list?

nattyweb’s picture

#8 did it for me - thanks danielphenry.