Skip to main content

Toggling block visibility according to content type

Occasionally, there is a need to show certain sidebar blocks only for nodes of a certain content type. In Drupal 6, this can only be done by using PHP for block visibility. The code looks like this:

<?php
// The machine readable type names to display the block for
$types = array('book','faq');
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node=node_load(arg(1));
if ($node!=NULL && in_array($node->type, $types)) return TRUE;
}
return FALSE;
?>