By HFlame7 on
In node.tpl.php I'm trying to show something if the term ID equals 5.
So it would be something like this:
if ($termID==5) {
//Show anything I want here
}Only problem is I do not know what the true PHP code for this is.
Any help is appreciated.
Thanks!
Edit:Here's the solution. Just posting it for everyone to see:
if (is_array($node->taxonomy))
{
if ( !empty($node->taxonomy[5]) )
{
//Show something because this node has a term whose ID is 5
}
}
I changed a few things, but the original source is: http://drupal.org/node/885198
Comments
$taxonomy array
You will need to process the $taxonomy array for the node.
I suggest you install the Devel module (http://drupal.org/project/devel) to see the data available on a node.
Can you paste a sample code
Can you paste a sample code of php? I did install the devel module, but have no idea how to get what I need from it.
Use dpm()
Your node.tpl.php probably has a line something like this:
<?php if ($taxonomy): ?><div class="taxonomy"><?php print $terms; ?></div><?php endif;?>You can modify that first part as follows:
<?php if ($taxonomy): dpm($taxonomy)?>Now when you visit a node with terms, you’ll see a nicely formatted structure you can navigate to understand what is available from the
node.tpl.phpfile.See you at the Drupalcon!
Sample PHP code
Right... well, that too...
I thought the question was "What does Devel do to help?" And that is that you can examine the structure of any variable, including the multidimensional arrays typical in Drupal, much more nicely than with a
var_dump()call.That said, your "example code" is much more likely to be close to the actual needs of the OP ;-)
See you at the Drupalcon!
I tried this code, but the
Spovlot, I tried this code, but the "print $term;" line prints "Array" instead of the values on nodes that have taxonomy terms assigned to them.
Any ideas on what would be causing this?
Thanks to both of you for the help and tips
(Customized) Solution
(Customized) Solution found:
I changed a few things, but the original source is: http://drupal.org/node/885198
Thank you both for helping me and the answers given