I wanted distinct taxonomy terms, so I could get a list of terms that have nodes. Attached is my solution.

CommentFileSizeAuthor
views_taxonomy.inc_.patch1.61 KBkonsumer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

konsumer’s picture

Assigned: Unassigned » konsumer

If anyone could review this, and let me know if it makes sense, that'd be awesome.

martink’s picture

I think that I am trying to do the same thing: that is to say, I want to design a block which displays the taxonomy terms associated with the most recent articles. Problem is, as far as I can see with Views 5.x-1.6, if several nodes have been classified under the same term then the term appears twice in the block. Is this what this patch is supposed to allow you to do?
I'm not qualified to validate the patch, but I think if you want to get it validated (and better still integrated into the next version of Views), then you need to give a lot more detail in your post: rationale behind the patch, what it allows you to do that you cannot do already, what is changed in the UI and the code. Also, is it an error that the patch is posted against version 5.x-1.x-dev? Should it not better be against 5.x-1.6 which is the latest stable version as I understand it?

kirby’s picture

I edited myself the file with your patch/diff file and here is the SQL error which is displayed :

user warning: Unknown column 'term_data.tid' in 'group statement' query: SELECT DISTINCT(node.nid) FROM node node GROUP BY term_data.tid LIMIT 0, 10 in C:\wamp\www\mysite\includes\database.mysql.inc on line 172.

I'm pretty sure I modified correctly the file.

ruanyf’s picture

kirby, you must add the filter "Taxonomy: Vocabulary Name" at the same time, then it will work.

kirby’s picture

It perfectly makes sens. it works now.
Thank you very much ruanyf.

xentek’s picture

Status: Needs review » Reviewed & tested by the community

Patch worked for me. This should be incorporated into the official release.

martink’s picture

Patch worked for me to I agree that this would be great in the official release

xentek’s picture

Now we just need COMMENT: DISTINCT and we'll be set :)

xentek’s picture

Re: Comment Distinct

I created a patch file to views_comment.inc that will add Comment:Distinct functionality. You can find it here: http://drupal.org/node/219499

Thanks goes to this patch author, as I used it as guide when developing mine! Props to konsumer!

lee20’s picture

Patch worked for me as well. Unfortunately I switched to using node reference instead of taxonomy. If only I can find a Node Reference Distinct filter now!

WorldFallz’s picture

+ 1. Patch applies cleanly and does what it says.

unfortunately, I can't seem to generate a simple list of distinct taxonomy terms.

I'm getting a list of terms for each node (1 node per row of terms), not a list of distinct terms.

I'm creating a page view as follows: "Taxonomy: Terms for " as the only field and "Taxonomy: Vocabulary Name" and "Taxonomy: Term Distinct" as the only filters. Nothing else it set.

What am I doing wrong?

Any insight would be greatly appreciated!

Thanks...

konsumer’s picture

If what you mean is that you want to get a list of terms, not attached to nodes, this is not what the patch provides. It's just a filter to show a term only once that is attached to a node. I think this is a basic part of how views works (everything is attached to a node.)

So what you should be getting is a list of all terms that have nodes assigned to them, listed only once.

This is useful, for example, for a catalog that uses taxonomy to categorize products. It will only show categories that have products in them.

If you mean something else, let me know, and I will have a look at your view.

WorldFallz’s picture

So what you should be getting is a list of all terms that have nodes assigned to them, listed only once.

yep... that's what I'm after--- I'm still learning my way around views, but Ive been doing some reading on d.o. and i think I need to use one of the summary options. maybe that's what I'm doing wrong. I don't have access to my system atm, but i'll give it another shot...

vanderlip’s picture

Konsumer - Thanks a lot! This works like a charm and solved my problem. Much appreciated.

joel_guesclin’s picture

Version: 5.x-1.x-dev » 5.x-1.6

Any chance of this getting into standard Views, it is so useful!!

enkara’s picture

I have a problem with this patch. When creating a view with pager, it counts all the items inside the categories, if as the view was without that filter. For example if I have two taxonomy terms with 14 items inside in total and the max items per page is 10, the pager is displayed and there are only two terms there...

Has someone found this and has fixed it? I would be fantastic for me.

Thank you very much!

sun’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Sorry, Views 1.x will not have any new major features. Consider upgrading to 6.x, please.

gthing’s picture

Aww please?