Scroll
Show block on pages of a certain type of content
!Legacy Drupal 7 code below!
Sometimes you need to display a block only on specific pages of a certain content type. In the standard block visibility settings, you can only configure visibility by path or user role. The following code, entered into the block visibility settings with PHP mode enabled, allows you to choose the content types on which the block will be shown.
<?php $match = false; if (arg(0) == 'node' && is_numeric(arg(1))) { $nid = arg(1); $node = node_load(array('nid' => $nid)); $type = $node->type; if (isset($types[$type])) { $match = TRUE; } } if (substr($_SERVER["REQUEST_URI"], 0, 6) == '/page/') { $match = TRUE; } if ($_SERVER["REQUEST_URI"] == "/node/add/page") { $match = TRUE; } return $match; ?>
For example, the block will be displayed on pages of the "Page" content type, as well as on the page creation form for that type. The $types
variable is an array of machine names of content types,