views:

30

answers:

1

I've created a variable in template.php that let's me print terms by vocabulary. The problem is that I want to be able to pass in a vocabulary id to select a specific vocabulary. My code looks like this:

function xnalaraart_classic_print_terms($node, $vocabularies){
    foreach($vocabularies as $vocabulary){
        if($terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid)){
            $output .= '<div>';
            $output .= '<ul class="links inline">';
            foreach ($terms as $term){
                $output .= '<li class="taxonomy_term_' . $term->tid . '">';
                $output .= l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
                $output .= '</li>';
            }
            $output .= '</ul>';
            $output .= '</div>';
        }
    }
    return $output;
}

and in the preprocess_node function:

$vars['terms_split'] = xnalaraart_classic_print_terms($vars['node']);

How do I write it so that I can pass in an id to $vocabularies?

+1  A: 

I think you made this more difficult on yourself than it really is. See below for final function.

function xnalaraart_classic_print_vocab_terms($node, $vid){
        if($terms = taxonomy_node_get_terms_by_vocabulary($node, $vid)){
            $output .= '<div>';
            $output .= '<ul class="links inline">';
            foreach ($terms as $term){
                $output .= '<li class="taxonomy_term_' . $term->tid . '">';
                $output .= l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
                $output .= '</li>';
            }
            $output .= '</ul>';
            $output .= '</div>';
        }
    return $output;
}

And then call

$vars['terms_split'] = xnalaraart_classic_print_terms($vars['node'], 10);  //Where 10 is the vocab ID
Chris Ridenour
I want to be able to use different vocabulary ids depending on node-type.tpl. That's why I want to be able to send an argument together with $terms_split.
Toxid
So in preprocess_node, use a switch statement. switch($vars['node']->type) { case 'page': $vars['terms_split'] = ....($vars['node'], 20); ... Make sense?
Chris Ridenour
Yes, that probably is the best solution. Is it impossible to send arguments with a node variable? Like $terms_split($vid)?
Toxid
I'm not sure what exactly you mean.
Chris Ridenour
I'm not good with php, I'm just wondering if it isn't possible to send the vocabulary id together with the $terms_split variable from the node.tpl.
Toxid