This is a trivial patch to the taxonomy_node_get_terms() function. Currently, it was only sorting the results by term weight; the patch joins in the vocabulary table and adds the vocabulary weight as a second preference ordering.

I wrote this because I wanted to force ordering of vocabularies when listing the taxonomies of a node using the taxonomy_link() function. Basically, what I was doing was this: I created a "Story Type" vocab which described the overall *type* of post ( News, Rant, Review, ... ) and a "Topic" vocab which described the *topic* of the post ( Programming, Math, Political, Family, ... ). Now, when you added a new story, you picked a Story Type and a Topic. When the story is displayed, it shows the taxonomy assignments as a list of links. The ordering of that list was by term weight, term name. That meant that if I wanted to control the left to right layout of that information, I'd have to set the weight on every term in each vocabulary. That seemed tedious, especially since the vocabularies themselves already had a weight associated with them. Hence, I dug around for about 15 minutes and wrote this patch.

It's been tested and seems to work quite well. I can now *force* which taxonomy vocabulary is listed when, and thereby always make the posts appear as "Story Type | Topic".

Hope it's useful.. :)

Comments

MrRoot’s picture

Ack - that patchfile was generated against the current CVS tree, so I suppose the Version should have been 'cvs'? Sorry about that if it was misplaced.

moshe weitzman’s picture

this patch makes a lot of sense ... however, your sql is non standard for drupal. we use the x JOIN y ON x.field = y.field syntax. Your SQL doe snot use this JOIN syntax. Please resubmit and then I'll bet that this will be accepted into core.

MrRoot’s picture

StatusFileSize
new872 bytes

Ah.. I was wondering about that.. Looks like most of the rest of taxonomy.module does not make use of JOIN statements. So I was following that. Anyhow, I updated the patch to use JOIN on all of the tables.

Cheers

dries’s picture

Is that ANSI SQL? If these are 'left' joins, please use 'LEFT JOIN'. If these are 'inner' joins, please use 'INNER JOIN'. Also, I'd add a small comment to code to explain the rationale behind that query.

killes@www.drop.org’s picture

Patch doesn't apply.

jonbob’s picture

Title: Patch for taxonomy module to improve ordering » Order taxonomy terms by vocabulary weight, then term weight
Category: bug » feature
grohk’s picture

StatusFileSize
new901 bytes

I have been looking for this funtionality for a long time, so I have attempted to bring this patch up-to-date and clean it up as per the suggestions.

grohk’s picture

StatusFileSize
new901 bytes

As per a suggestion Moshe made in an email, I have updated this patch to order by vocabulary weight then term weight.

dries’s picture

Committed to HEAD. Thanks.

Anonymous’s picture