Drupal - Displaying a block only for nodes of a specific content type, how do I check the content type using PHP?

// Only show if $match is true
$match = FALSE;

// Which node types
$types = ['kYn'];

// Match current node type with array of types
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load($nid);
  $type = $node->type;
  $match |= in_array($type, $types);
}

return $match;

source : http://drupal.org/node/115419


To expand on sheena_d's comment:

In Drupal 7 showing a block for one or more specific node types is available out of the box, with no need to write any PHP.

Where you would normally add PHP in the block 'visibility settings' select 'content types' from the menu on the left. Then select the content types you wish the block to display on.

I hope this helps simplify this for someone.

Where you would normally add PHP in the block 'visibility settings' select 'content types' from the menu on the left.

Then select the content types you wish the block to display on

Tags:

Nodes

7