Not sure if this is posted in the right forum, feel free to move it if need be.

I know a lot of people are after a Views Glossary page to display taxonomy terms, and from looking on the forum i have realised a lot of people are having trouble creating such a View thats in working order,

So i have created one for you to use if you need to, this was created on Drupal 6 using Views 2.

Heres a little description of the layout i used and a screen shot of the final view is included as well as the code used (you can use the code to import into views).

Image: Click to see the image
Basically, my site is a music site, a person uploads a music file and they Provide the node with an ARTIST name in a freetagging taxonomy field.
The tags for all songs uploaded to the site are saved under ARTIST (field_artist_tax). Users can then select an artist from the taxonomy list and clicking on it will provide them with all the songs related to that artist.

What my views does, is it provides a page where a user can click on a letter, and the views uses Ajax to display without refresh all the taxonomies beginning with that letter: (look at the image provided)

And here is the code: :)


$view = new view;
$view->name = 'gloss_temp';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'term_data';
$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', 'Defaults', 'default');
$handler->override_option('fields', array(
  'name' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_taxonomy' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'name' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'ignore',
    'glossary' => 1,
    'limit' => '1',
    'case' => 'upper',
    'path_case' => 'lower',
    'transform_dash' => 0,
    'add_table' => 0,
    'require_value' => 1,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => 'a',
    'default_argument_user' => 0,
    'default_argument_image_size' => '_original',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'audio' => 0,
      'faq' => 0,
      'image' => 0,
      'artistpage' => 0,
      'event' => 0,
      'music' => 0,
      'page' => 0,
      'profile' => 0,
      'story' => 0,
      'video' => 0,
      'webform' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '5' => 0,
      '8' => 0,
      '9' => 0,
      '10' => 0,
      '6' => 0,
      '4' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
      'thumb_scale' => 'thumb_scale',
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'vid' => array(
    'operator' => 'in',
    'value' => array(
      '8' => '8',
      '9' => '9',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'vid',
    'table' => 'term_data',
    'field' => 'vid',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Music By Artist');
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 54);
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
  'grouping' => '',
  'columns' => '6',
  'alignment' => 'horizontal',
  'fill_single_line' => 1,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'music/by/name');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->override_option('arguments', array(
  'name' => array(
    'default_action' => 'summary asc',
    'style_plugin' => 'unformatted_summary',
    'style_options' => array(
      'count' => 0,
      'override' => 0,
      'items_per_page' => '25',
      'inline' => 1,
      'separator' => '|',
    ),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'glossary' => 1,
    'limit' => '1',
    'case' => 'upper',
    'path_case' => 'lower',
    'transform_dash' => 1,
    'add_table' => 0,
    'require_value' => 1,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => 'a',
    'default_argument_user' => 0,
    'default_argument_image_size' => '_original',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'audio' => 0,
      'faq' => 0,
      'image' => 0,
      'artistpage' => 0,
      'event' => 0,
      'music' => 0,
      'page' => 0,
      'profile' => 0,
      'story' => 0,
      'video' => 0,
      'webform' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '5' => 0,
      '8' => 0,
      '9' => 0,
      '10' => 0,
      '6' => 0,
      '4' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
      'thumb_scale' => 'thumb_scale',
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('attachment_position', 'both');
$handler->override_option('inherit_arguments', 0);
$handler->override_option('inherit_exposed_filters', FALSE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'page_1' => 'page_1',
  'default' => 0,
));

Comments

prezaeis’s picture

forgot to mention, the views will not provide letters if there are no terms associated with a letter

also if you have a term available but there are no nodes under it then it will still be visible

fadgadget’s picture

thanks very much. I was struggling a bit there. Works a treat straight out the tin.

prezaeis’s picture

Your welcome :)

canadrian’s picture

Oh my God, you saved my life. I've been banging my head against the desk here for hours and couldn't get this working. Wish I'd searched for a pre-made view in the first place. Funny thing is I can't see what the difference is between what you made and what I was trying, but whatever... it works now. Thanks so much!

prezaeis’s picture

your welcome :) glad it helped

lahode’s picture

Not really sure either it's the place to post, put it really helped me sort the trick with glossary configuration in arguments

Thx

Fredrik Lahode
Développeur et Formateur web indépendant

prezaeis’s picture

Glad it worked :)

meeta’s picture

Thanks for the great help. Can you help me in editing the view so that only the top level terms of any stated vocabulary is included in glossary. Example: Suppose Vocabualry= Location, Parent terms: Asia, Africa, America n Europe. So what I need is that glossary should display only A|E in this case.

Quick response will be appreciated. Thanks in advance.

Meeta

andrés chandía’s picture

Drupal 7.21
Views 7.x-3.5

The things I've changed:
Title: None
Grid Settings: Number of columns * =1
Filter criteria: Taxonomy term: Vocabulary (= Translator)
Page settings: Path: /translators-alphabet

If I go to the page I see the letters and all the names, if I click one of the letters it does nothing, even though the link shows that is going to /translators-alphabet/t for instance, it does not go, so if I type it manually it shows a blank page.

If I go to the attacment preview and I click the letter from there it also sends me to a blank page.

At some points the system shows me this message:
Notice: Undefined property: views_many_to_one_helper::$placeholders in views_many_to_one_helper->add_filter() (line 1032 of .../sites/all/modules/views/includes/handlers.inc).

I would appreciate a lot if you could help me on this.
Thanks

@ch

andrés chandía’s picture

I change ajax to no in the page view and that did it, so if somebody is interested in this kind of view I paste mine here, I hope it helps.

$view = new view();
$view->name = 'trans_trans_alphabetic';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Trans&Trans Alphabetic';
$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['title'] = 'Trans&Trans Alphabetic';
$handler->display->display_options['use_ajax'] = TRUE;
$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'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* 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']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = TRUE;
/* 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']['default_action'] = 'default';
$handler->display->display_options['arguments']['name']['exception']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['name']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['name']['default_argument_options']['argument'] = 'a';
$handler->display->display_options['arguments']['name']['summary']['number_of_records'] = '0';
$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']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['name']['glossary'] = TRUE;
$handler->display->display_options['arguments']['name']['limit'] = '1';
$handler->display->display_options['arguments']['name']['case'] = 'upper';
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['filters']['machine_name']['field'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['value'] = array(
  'translator' => 'translator',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* 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']['exception']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['name']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['name']['default_argument_options']['argument'] = 'a';
$handler->display->display_options['arguments']['name']['summary']['number_of_records'] = '0';
$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']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['name']['validate']['fail'] = 'ignore';
$handler->display->display_options['arguments']['name']['glossary'] = TRUE;
$handler->display->display_options['arguments']['name']['limit'] = '1';
$handler->display->display_options['arguments']['name']['case'] = 'upper';
$handler->display->display_options['arguments']['name']['require_value'] = TRUE;
$handler->display->display_options['path'] = 'trans-trans-alphabetic';

/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* 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']['default_action'] = 'summary';
$handler->display->display_options['arguments']['name']['exception']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['name']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['name']['default_argument_options']['argument'] = 'a';
$handler->display->display_options['arguments']['name']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['name']['summary']['format'] = 'unformatted_summary';
$handler->display->display_options['arguments']['name']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['name']['summary_options']['inline'] = TRUE;
$handler->display->display_options['arguments']['name']['summary_options']['separator'] = '| ';
$handler->display->display_options['arguments']['name']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['name']['glossary'] = TRUE;
$handler->display->display_options['arguments']['name']['limit'] = '1';
$handler->display->display_options['arguments']['name']['case'] = 'upper';
$handler->display->display_options['arguments']['name']['transform_dash'] = TRUE;
$handler->display->display_options['arguments']['name']['require_value'] = TRUE;
$handler->display->display_options['displays'] = array(
  'page' => 'page',
  'default' => 0,
);
$handler->display->display_options['inherit_arguments'] = FALSE;
$handler->display->display_options['render_pager'] = TRUE;

@ch

dean.p’s picture

Just like to say a big thanks! Saved me a few hours to say the least ;)

Update: Sorry, I get the following error on the resulting page:
Warning: Creating default object from empty value in views_many_to_one_helper->summary_join() (line 865 of ...\sites\all\modules\views\includes\handlers.inc).

bpadaria’s picture

For sharing glossary view.

It works without any issue.