views:

168

answers:

2

Hi, i have build an "About the Author" views block in Drupal. This is linked at the user_id of the creater of the current node, which works great.

However, i now would like to know how to limit the view to certain content types. I do not want it to show on a story, only on blogs. I tried to do it with Arguments but i haven't had any luck so far.

Can anyone help me out?

A: 

Simply create your view, go to the block configuration page and use php for the block visibility rules. To show the block only on certain content types, use:

<?php
$match = FALSE;
$types = array('story' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if (isset($types[$type])) {
    $match = TRUE;
  }
}
return $match;
?>

This code is taken from drupal.org, Overview-approach to block visibility

marcvangend
+2  A: 

I recommend using pathauto to give each node of the type a common URL prefix (a good idea anyway), so you can use a simple block visibility path restriction. For example, you set your content type path pattern to "article/[title]" and then set your block path to "article/*"

Scott Reynen
I like this approach, because it is less likely to break after upgrading to a newer drupal version.
FlorianH