Posted by nicktr on July 12, 2011 at 4:27am
I want to reverse the order of the taxonomy terms that appear on a node, as it's a more logical order of the hierarchy.
i.e. I want the highest level first, filtering down to the lowest.
Glass & Porcelain >> Antique Mirrors >> Antique Gilt Mirrors
instead of the other way:
Antique Gilt Mirrors >> Antique Mirrors >> Glass & Porcelain
In the node.tpl.php file I have located where the terms are called:
<div class="links-wrapper">
<?php print $links; ?>
<?php if ($terms): ?>
<div class="terms terms-inline"><?php print t(' <div class="taxonomy-wrapper"> Posted in ') . $terms . (' </div>'); ?></div>
<?php endif; ?>
</div>How do I manipulate the $terms array (is it an array?) to reverse the order.
If it's array can I just the array_reverse function? If so, how?
Thanks in advance!
Nick

Comments
preprocess_node hook?
Try to use the preprocess_node hook in template.php, you should be able to reverse it at some stage, taxomomy terms must be store in the vars['terms'] variable.
Well, how you organize the
Well, how you organize the order of your terms in your vocabulary? If your terms are like a tree, I think the $terms variable have to display the terms in the same order. If the order is like:
-Gilt Mirrors
----Antique Mirrors
--------Glass & Porcelain
and you want to display Gilt Mirrors >> Antique Mirrors >> Glass & Porcelain, I think you have to select all values (or use http://drupal.org/project/hierarchical_select module to select only one value but record all parents terms in your database). With that, your $terms will contain all temrs in the right order (or if it's not that, I missed something in your explanation :))
Julien Didelet
Founder
Weblaa.com
You can alter the order
You can alter the order at
D6:
admin/content/taxonomy/[vid]
D7:
admin/structure/taxonomy/[vocabulary_name]
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
Oh this is a hierarchy. I'm
Oh this is a hierarchy. I'm not totally sure, but I think you are describing a hierarchy like this
Glass & Porcelain|---Antique Mirrors
|----Gilt Mirrors
Where gilt mirrors are a type of antique mirror, which falls under glass & porcelain. If you set up the vocabulary like that it should display as you are hoping:
Glass & Porcelain >> Antique Mirrors >> Antique Gilt Mirrors
Is that not happening?
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
it is actually a very complex
it is actually a very complex thing.
First, by selecting "Antique Gilt Mirrors", actually "Glass & Porcelain" and "Antique Mirrors" is not a term of the node. You only save the one you selected unless you "mult-select" them explicit-ly. You need Hierarchical Select module to fix above
Second, the order of terms in $terms is in order of "weight". But parent-child weight need no to be in correct order, the first child's weight is always zero.
Joetsui's blog
Thanks for the comments
Thanks for the comments guys.
Joe, I am in fact using hierarchical select already.
Dave you're right,
The top level term is Glass and Porcelain, then first sub level is Antique mirrors, then second sub level is Antique gilt mirrors.
But you can see in screen shot here: http://cl.ly/3f0y1q3E1q3o40232609 (i added the arrows with CSS, not Hierarchical select)
The order comes out in reverse. It's not a huge problem but I think it makes more sense to have the top level term first
In the Hierarchical select settings i've chosen to save the term lineage to the node, hence it outputs the terms from each of the 3 levels.
Any other thoughts?
Then doing this in
Then doing this in node.tpl.php is too late in the game, it's already been converted into a big long string including the links. You need to hook into the process while it's still a big array of links. On the theme layer you could implement hook_node_view_alter() or in a module you could implement hook_node_view()
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
Or what you are really trying
Or what you are really trying to do here is create breadcrumbs. You might look at the Custom Breadcrumbs module.
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
Thanks Dave, I'll look into
Thanks Dave, I'll look into both those options.
Nick