suppose i create a block and want to print out something when the content is showing a certain type of node, say, blog. how to code it in the block? i wrote this: print $node->type; and show nothing. how to get the current node type?

thanks a lot.

Comments

leadstudios’s picture

looks like the right code. where did you put the print statement?

nevets’s picture

Blocks do not have a $node variable, if you want the block to do something based on the current node you need something like

<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  if ( $node->type == 'xyz' ) {
    // Do something for nodes of type 'xyz'
  }
}
?>
Rob T’s picture

Thanks for the tip, nevets.