Exclude the current node from a list view

In some situations, for example a block listing nodes related to the node being viewed, you might wish to exclude the current node from a list view.

Using Views module, add a "Node:ID" argument type to your view. In the Option dropdown, select "Not Equal". Then place the following in the Argument Handling Code:

if ( ($type=='block') && is_numeric(arg(1)) ){
  $args[0] = arg(1);
}

return $args;

Adapted from this forum post: http://drupal.org/node/131482

 
 

Drupal is a registered trademark of Dries Buytaert.