Associate Blocks with Forum nodes

If you want show a node in all node forums, thanks to new feautre of Drupal 4.7 (Show block on specific pages) It's very simple:
First from "Show block on specific pages" section of block setting choose "Show if the following PHP code returns" and then put following snippet in Pages Box:

<?php
if (arg(0) == 'node') {
 
$node = node_load(array('nid' => arg(1)));
  return
$node->type == 'forum';
}
?>

It's useful for showing showing Active forum topics' and 'New forum topics' blocks in all forum posts.

To reverse this

change this line

return $node->type == 'forum';

to this:

return $node->type != 'forum';

I believe this does what you asked for, rt.

Sidebar: I became confused while I tested this, because my test block did not show on admin pages. Of course! Admin pages aren't nodes!

I used this snippet in <?php

forngren - February 26, 2007 - 21:37

I used this snippet in <?php block visibility:

<?php
 
return (arg(0) == 'node' &&  is_numeric(arg(1)) && node_load(arg(1))->type=='blog');
?>

Simply replace "blog" with name of your content type. For multiple content types, use this syntax:
<?php
 
return (arg(0) == 'node' &&  is_numeric(arg(1)) && (node_load(arg(1))->type=='blog' || node_load(arg(1))->type=='page' || node_load(arg(1))->type=='etc')));
?>

I don't think it's the cleanest and most optimized solution, but it's quick, dirty and works.
Crossposted from http://johan.forngren.com/show-blocks-only-on-certain-content-type.

Another solution

tulvur - December 16, 2007 - 18:59

Based in that article, I've done this to show a block in blog frontpages and nodes:

<?php
if (arg(0) == 'node') {
 
$node = node_load(array('nid' => arg(1)));
  return
$node->type == 'blog';
} else {
  return
arg(0) == 'blog';
}
?>

This shows on all pages that are not images

mikemee - March 7, 2007 - 07:43

I couldn't get the shorter versions in the preceding comments to work in Drupal 5, but this slightly longer version did:

<?php
 
if (arg(0) == 'node' ) {
   
$node = node_load(array('nid' => arg(1)));
      return
$node->type <> 'image';
} else {
  return
TRUE;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.