Posted by susanbcampbell on August 4, 2010 at 3:10pm
I've installed/enabled Hierarchical Select and it does just what I need on the form. Unfortunately the results are stored in the reverse order from what I need, i.e. the deepest item is returned first. They are grouped correctly, i.e. version, version, product, version, product, company, but I need them to be company, etc. How do I go about reversing this order? I've read the README for Hierarchical Select and the section on "Rendering hierarchy lineages when viewing content", but I'm pretty new to this and don't really understand what to do. Can someone help me out? Thanks.
Comments
Can you give a URL or a
Can you give a URL or a screen grab?
Ryan Price
DrupalEasy Podcast
HS display
Here's a link that demonstrates the behavior: http://fage.dev2.webenabled.net/
sc
You might need to do some PHP
You might need to do some PHP coding. The Terms get rendered during hook_preprocess_node(). You can override this function in your theme.
Create a new function in your template.php in your theme, and replace the word "template" in the function name with the name of your theme, as below.
http://api.drupal.org/api/function/template_preprocess_node/6
Assuming you're using the "Zen" theme:
<?php
function zen_preprocess_node(&$variables) {
// any changes you make to the $variables array will change what is available to the node.tpl.php file
if (module_exists('taxonomy')) {
$variables['taxonomy'] = taxonomy_link('taxonomy terms', $node);
}
else {
$variables['taxonomy'] = array();
}
//maybe instead of running all the terms through theme('links'...) you'd rather do something else here.
$variables['terms'] = theme('links', $variables['taxonomy'], array('class' => 'links inline'));
}
?>
The other way to do it would be to write some PHP in your node.tpl.php
Since you have that $taxonomy variable as well as the current $terms that is being printed out, you already have an array with all of your terms (but as you say, in the wrong order). There is a php function called array_reverse() that could help:
http://php.net/manual/en/function.array-reverse.php
You also might only want to make this change for a certain node type:
<?phpfunction zen_preprocess_node(&$variables) {
if($variables['node']->type == "blog") {
$variables['terms'] = theme('links', array_reverse($variables['taxonomy']), array('class' => 'links inline'));
}
}
?>
Ryan Price
DrupalEasy Podcast
PHP fix doesn't work for me
Thanks for your help. I tried both, but mainly focused on the node.tpl.php solution. I know I'm in the right node.tpl.php. I confirmed that by adding dpm($node); to the page. I also used the dpm output to be sure I have the right node type to replace "blog" in the example you sent -and the right theme name, in my case tendu_default. Is there a specific spot to put this in the node.tpl.php or could there be something else I'm missing? Do I need to use the name of the field that holds the array of terms I want to reverse? Sorry I haven't been able to make it work.
Additionally, when it does work, would it affect the output created by Views? There I'm able to use Format as Hierarchical Text and it works fine. Although, I suppose, if I can reverse the array, then I could just use Format as Text and it would be in the right order if it's coming from the same place.
sc
Looks like the terms might be
Looks like the terms might be stored in an associative array. I don't think those really care about the order they're in.
Try putting the array_values() function in there too...? That should convert the array to an indexed array....
<?phparray_reverse(array_values($variables['taxonomy']));
?>
Ryan Price
DrupalEasy Podcast