How can I show a block on a specific content type programmatically? I want in my image the 'basic page' selected.
I used the xxx_block_info() function, should it set in here?
If you look at the node_module file it controls the node type visibility using the hook_block_list_alter.
So basically it might looks something like this. NOTE: This is a non tested version.
function hook_block_list_alter(&$blocks) {
$node = menu_get_object();
// list of all block deltas u want to apply this
$block_delta = array('deltas');
foreach ($blocks as $key => $block) {
if (!empty($node) && $node->type == 'page' && in_array($key, $block_delta)) {
unset($blocks[$key]);
continue;
}
}
}
You can do like this:
function xxx_block_info() {
$blocks['xxx'] = array(
'info' => t('Xxx'),
'visibility' => BLOCK_VISIBILITY_PHP,
'pages' => '<?php global $node; if ($node->type == 'yyy') return TRUE; else return FALSE; ?>'
);
}
Verify that the PHP filter module is enabled if you want to use BLOCK_VISIBILITY_PHP!