I want to display a list of taxonomy terms of published nodes alphabetically but some terms are duplicated because the same terms are tagged to different nodes. How to create a view to display unique taxonomy terms of published nodes alphabetically?

My View:

View Type : node
Basic settings 
  Style: Grid
  Row style: Fields

Fields
  Taxonomy: Term

Filters
  Node: Published Yes 

Comments

dawehner’s picture

You need a view type: taxonomy, for listing taxonomy terms.

Anonymous’s picture

Actually that doesnt exactly do it

I have recently had the same problem. I wanted a list of Authors Names which were in a taxonomy , which i would then use the name as the argument in a second view so when i selected the name i got the page for the other view.

If you use the view type taxonomy it returns all taxonomy terms, including those with "0" results what xn 2001 wants is only those where there are results , ie used in nodes published

So First a feature to ignore those without taxonomy entries ie zero, for taxonomy views would be great

Alternatively the way i found to eliminate the duplicates is as follows, but you cant display it as a grid, you get a single column

Are we sitting comfortably ?
Basic Settings - row style - fields
Fields - Taxonomy Term
Basic Settings - style - Grid settings - Goup on Taxonomy Term

In your Filters select Node Published Yes and anything else you want

xn2001’s picture

@dereine
No, I can't set the view type to taxonomy term because I need to set node filter to Published. When using "Taxonomy term" view type, informations about the node are not exposed. Therefore, I have to use Node view type.

@midkemia
Your suggestion doesn't work. Actually, it is getting worst. By grouping on Taxonomy Term, I first get the group name and also the duplicate terms.

Anyone has other suggestions?

Anonymous’s picture

Did you just look at the preview or the view results?

You will see the duplicate terms in preview, but not in the actual page view. OK thats what happens in my case

EDIT : just remembered i also themed

views-view-grid--myview--page.tpl.php

<?php
// $Id: views-view-grid.tpl.php,v 1.3 2008/06/14 17:42:43 merlinofchaos Exp $
/**
 * @file views-view-grid.tpl.php
 * Default simple view template to display a rows in a grid.
 *
 * - $rows contains a nested array of rows. Each row contains an array of
 *   columns.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)) : ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>

So I guess i cheated to get rid of the surplus

xn2001’s picture

@midkemia
I looked at both, the preview and the results views. They both showed the duplicate terms. Your suggestion doesn't satisfy my need as it forces all terms into 1 columns. I want to show terms in 4 columns.

Is there a hook where I can remove the duplicates before the results are submitted to view?

xn2001’s picture

Status: Active » Closed (fixed)

Ok, I finally resolved my issue by using hook_views_pre_render(&$view) to remove duplicate terms before view is rendered. I think it is much elegant than other workarounds.

olafveerman’s picture

Can you provide a bit more detail as to how solved it? It might benefit others that have the same problem, myself included.

xn2001’s picture

@oBirdman
What I did was:
In hook_views_pre_render(&$view), I loop through $view->result array and check whether the next term is the same as the current term. If it is, then I remove the array index. Otherwise, go to the next term.

Note: What I did is not full proof. Duplicate terms are removed but not replaced. If you set 10 terms per page and 10 of them are the same terms, then you get a page with only 1 term because the remaining 9 are duplicates.

pharma’s picture

When you first create a view, select Taxonomy Terms as the type instead of Node.

http://drupal.org/node/350977#comment-1174041

Anonymous’s picture

pharma #9 see derine's response #1

Also my response in 2, your suggested method does not meet the requirement.

Using your method a Taxonomy Term with zero results is still returned.

It also does not take account where a Taxonomy is used across multiple content types and the results of only 1 content type is needed