where the $terms are printed, can I restrict it to terms only from one vocabulary?

thanks!

Comments

lluser’s picture

No one?

masher’s picture

<?php
/**
* Prints an unordered list of the terms (as links) that are
* associated to the currently displayed node.
* Cut n Paste into your theme's node.tlp.php file
* $vid = vocabulary ID number

*/
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    $node = node_load(arg(1));
    $vid = 4;
    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    if ($terms) {
print '<ul>';
                foreach ($terms as $term) {
                print '<li>'.l($term->name, 'taxonomy/term/'.$term->tid).'</li>';

          }
print '</ul>';
    } 
}
?>
mathieu_ch’s picture

Hi,
Thanks for the script.
I experienced conflicts with this script and Contemplate. The script was inserted in a tpl.php page already customized to call specific values using the contemplate module (disk mode).

The node_load function kept other contents being printed (I'm not sure how or why,but it shut out all custom content).

Anyway, I commented the node_load line, making it look like this. Everything went fine.

<?php
/**
* Prints an unordered list of the terms (as links) that are
* associated to the currently displayed node.
* Cut n Paste into your theme's node.tlp.php file
* $vid = vocabulary ID number
*/
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    // $node = node_load(arg(1));
    $vid = 4;
    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    if ($terms) {
print '<ul>';
                foreach ($terms as $term) {
                print '<li>'.l($term->name, 'taxonomy/term/'.$term->tid).'</li>';

          }
print '</ul>';
    }
}
?>

I'm just a beginner at PHP, is it kosher? How do I keep all this logic in template.php and only call it in tpl.php?

mathieu_ch’s picture

Hi,
Thanks for the script.
I experienced conflicts with this script and Contemplate. The script was inserted in a tpl.php page already customized to call specific values using the contemplate module (disk mode).

The node_load function kept other contents being printed (I'm not sure how or why,but it shut out all custom content).

Anyway, I commented the node_load line, making it look like this. Everything went fine.

<?php
/**
* Prints an unordered list of the terms (as links) that are
* associated to the currently displayed node.
* Cut n Paste into your theme's node.tlp.php file
* $vid = vocabulary ID number
*/
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    // $node = node_load(arg(1));
    $vid = 4;
    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    if ($terms) {
print '<ul>';
                foreach ($terms as $term) {
                print '<li>'.l($term->name, 'taxonomy/term/'.$term->tid).'</li>';

          }
print '</ul>';
    }
}
?>

I'm just a beginner at PHP, is it kosher? How do I keep all this logic in template.php and only call it in tpl.php?

halloffame’s picture

<?php print $node->content['body']['#value']; ?> does not render in the presence of this code in the template files.

cookiesunshinex’s picture

Thanks masher.

This is exactly what I was looking for.

subir_ghosh’s picture

Thanks Mike. This was a great help.

Ed: I too needed to modify as Mat had to.

-----------------------------
Subir Ghosh
www.subirghosh.in