Drupal: Using taxonomy term to control block visibility

Documenting this code, it was useful in a recent project

Displays a block on node or listing page

<?php
     $make_block_visible = FALSE;
     // the term id to show this block on
     $term_id_to_trigger_show_block = 1;
     // LISTING PAGE. taxonomy/terms/x
     if ((arg(0) == 'taxonomy') && (arg(1) == 'term') && (arg(2) == $term_id_to_trigger_show_block)) {
          $make_block_visible = TRUE;
     }
     // NODES
     if (arg(0) == 'node' && arg(1) && is_numeric(arg(1))) {
          $node = node_load(arg(1));
          foreach ($node->taxonomy as $term) {
               if ($term->tid == $term_id_to_trigger_show_block) $make_block_visible = TRUE;
          }
      }
      return $make_block_visible;
?>

Reference http://drupal.org/node/320795

  1. No comments yet.

  1. No trackbacks yet.

You must be logged in to post a comment.

Valid XHTML 1.1