I would like to have a block with stuff in it only display in one content type but am not sure what I should put in the php.

I have searched the forums already and got the following codes from two places

$types = array('forum' => 1);

  if (condition) {
    return TRUE;  // block will be shown
  }
  return FALSE;

Does anyone know how I can use this code or maybe make a new one to display a block only on certain content types?

Thanks.

Comments

matt_harrold’s picture

  // are we on a node display page?
  if((arg(0)=='node') && (is_numeric(arg(1)) && (arg(2)!='edit')){
    // load the node ... 
    $node=node_load(arg(1));
    if($node){
      // check out what type it is ... returns TRUE if it's your desired content type.
      return ($node->type=='MyContentType');
    }
  }
  return FALSE;
blavish’s picture

Hi, thanks for that code but it wont work for some reason on my blog. I changed the MyContentType to story but couldnt get it working.

andrew.eatherington@gmail.com’s picture

In Home › Administer › Site building › Blocks

select: Show if the following PHP code returns TRUE (PHP-mode, experts only).
paste in (edit to requirements)

    if($node->type=='page' || drupal_is_front_page()){
      return TRUE;
    }
Kylian-1’s picture

I have Drupal 6 and it doesn't work.
I've found another post with more complex code, but working:
http://drupal.org/node/355959