Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am not a dev, but am trying to show and hide a div for on a particular node type node.tpl.php file based on taxonomy term value.

can someone please let me know how to do this.

*I AM ADDING THE ANSWER HERE AS I AM NOT ELIGIBLE FOR ANSWERING *

I have a div which prints the taxonomy value of a node (where 30 is the vacabulary ID):

    <div class="node-r-status-tid-0 <?php print $term_css;?>">
        <?php print THEME_NAME_taxonomy_list($node, 30); ?>
    </div>

Below is the PHP code to make the dive show and hide:

    <?php 
    if ($node->taxonomy[868])
      $tid = 868;  // This should be the taxonomy term id that you want to theme on
        foreach ( (array)$node->taxonomy as $term ) {
          if ( $term->tid == $tid ) {
            $term_css = " node-r-status-tid-" . $term->tid;
            break;
          }
        }

    if($node->taxonomy[869])
      $tid = 869;  // This should be the taxonomy term id that you want to theme on
        foreach ( (array)$node->taxonomy as $term ) {
          if ( $term->tid == $tid ) {
            $term_css = " node-r-status-tid-" . $term->tid;
            break;
          }
        }
    ?>

Using css classes I make the dive display:block or none.

Please let me know if the above code can be fine tuned further

Thanks, Anand

share|improve this question
    
Please post the DIV structure. –  GoodSp33d Oct 22 '12 at 11:15
    
it is just a normal div with static content in it. –  AnAnD Oct 22 '12 at 11:41
    
Please post the taxonomy links html structure and div you are talking about.. Ideal way is using jquery you can do that !! –  Anil Sagar Oct 22 '12 at 11:50
    
I think I got it now... There is a div in node.tpl.php file, lets say eg: <div class="node-r-status-tid-0 <?php print $term_css;?>">Some content</div> –  AnAnD Oct 22 '12 at 11:57
    
I have added this code <?php if ($node->taxonomy[868]) $tid = 868; foreach ( (array)$node->taxonomy as $term ) { if ( $term->tid == $tid ) { $term_css = " node-r-status-tid-" . $term->tid; break; } } if($node->taxonomy[869]) $tid = 869; foreach ( (array)$node->taxonomy as $term ) { if ( $term->tid == $tid ) { $term_css = " node-r-status-tid-" . $term->tid; break; } } ?> –  AnAnD Oct 22 '12 at 12:00

1 Answer 1

up vote 0 down vote accepted

In Drupal 6 add somthing like this to your template.

foreach ($node->taxonomy as $term ) {
  if ($term->tid == YOUR_TID) {
     print "<div>...</div>";
  }
}
share|improve this answer
    
Thanks a lot it works.. :) I was trying to round, round and round to get to my destination :D –  AnAnD Oct 23 '12 at 5:44
    
You're welcome. Please mark the answer as your accepted answer. –  kamyar Nov 1 '12 at 15:42
    
answer accepted, thanks again –  AnAnD Dec 5 '12 at 11:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.