Hi all

have a problem with the way my tags are displayed on a custom template. Am using the code

 <?php

$firstterm = 0;
foreach ((array)taxonomy_node_get_terms_by_vocabulary($nid, 6, $key = 'tid') as $term) {  if ( $firstterm > 0 ) { print ", ";}  print "<a href=\"/cars/" . taxonomy_term_path($term) . "\">$term->name</a>";
  $firstterm++;} ?>

to display the terms, the problem is on some categories they print reverse alphabetical and others with no alphabet sorting.

In reality I want them to print in exactly the way that the user typed them in the first place. Would anyone have any ideas on this? Have tried changing the order in taxomonony module, but seems to make no difference.

Comments

knight42’s picture

just wanted to post a screenshot of what it looks like when the custom node is seen, this is driving me insane, i guess im missing something, but i cant find out what! So if anyone could help id be most greatful!

http://img516.imageshack.us/img516/4880/51293377nc2.jpg

mooffie’s picture

I want them to print in exactly the way that the user typed them in the first place.

It's not possible with the built-in tools. It requires programming.

The order of the terms has to be recorded somewhere. There's a column in the DB that records the weight of each term. The taxonomy module sorts the terms first by this weight and then alphabetically by the name of the term.

The free-tagging terms, when created, are all assigned the same weight, so you have no luck here: they will be sorted alphabetically. Besides, even if you wrote a module to assign incrementing weights to the tags entered --so that they'd be sorted "in the order the user typed them"-- there's still the problem of a user typing "cat" again in the future: only one weight can be associated with a term, so even if this "cat" appeared in the right place in one listing, it would appear in the wrong place in another.

the problem is on some categories they print reverse alphabetical and others with no alphabet sorting.

I had a look at `taxonomy_node_get_terms_by_vocabulary()'. This function sorts the terms in this manner: '... ORDER BY weight'. It doesn't sort them in this manner: '... ORDER BY weight, name'. That's strange, because most other queries in this module do sort by name afterwards. I wonder if this is a bug (consider filing an issue!). So, since your terms all have the same weight, I'd say you get them in an "unspecified" order. It seems this "unspecified" order sometimes results in the "reversed" order you see.

If you want an alphabetical order, either use some other function to get the terms, or sort them yourself.

BTW, have a look at:
http://drupal.org/project/term_display
http://drupal.org/project/taxonomy_redirect