Display terms only from one vocabulary
stellarvisions - January 15, 2009 - 16:54
where the $terms are printed, can I restrict it to terms only from one vocabulary?
thanks!
where the $terms are printed, can I restrict it to terms only from one vocabulary?
thanks!
No one?
No one?
This worked for me
<?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>';
}
}
?>
Glitches with Contemplate (disk mode)
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?
Mat
Glitches with Contemplate (disk mode)
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?
Mat