0

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

  • 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
0

In Drupal 6 add somthing like this to your template.

foreach ($node->taxonomy as $term ) {
  if ($term->tid == YOUR_TID) {
     print "<div>...</div>";
  }
}
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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