Okay, so I found this discussion from 2005 about a patch that would allow a block to only display on a specific node type - http://drupal.org/node/16074 - but does anyone know if this would still work for D6?

I want to add blocks to a specific node type - so this is exactly what I'm looking to do.

Would I need to write a php script to filter this? HELP!! :D

Comments

roopletheme’s picture

No patch needed... just change the block's Page specific visibility settings to 'Show if the following PHP code returns TRUE', and add this PHP code just below this setting:

if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
  $thenode = node_load(arg(1));
  if ($thenode->type == 'blog') {
    return TRUE;
  }
}

This code will display the block for nodes of type blog... change the node type to suit your needs.

GreenSpiderDesign’s picture

Thank you so much roopletheme!!

yakker’s picture

:)

fresh-off’s picture

this works great, except for that I’d like the block to show for nodes of type “blog” AND also on specific pages – in my case www.mysite.com/blog which is a view showing a list of blogs. How can I do both?

vikramy’s picture

Use same logic.

if ( arg(1) == NODE_ID_OF_BLOG)
return TRUE;

fresh-off’s picture

COOL!
but how the heck do i find the Node ID of a View? been googling around for that and i keep coming up short. how might i use the same logic, but to check for a URL, rather than NID?

vikramy’s picture

My Bad... I misread that. If its a view, then

$url = request_uri();
if (strpos($url, "blog")) {
 return TRUE;
}

Basically any URL check you can use something like this. Hope this helps.

fresh-off’s picture

works perfectly!!!!!