Php arguments in Views for Drupal can be the answer you need to getting your views to output correctly. Follow along as I go through a handful of very useful php arguments for Views.

I don't claim to fully understand Php and php arguments. I'm still learning, but what I do know I'm glad to share with those willing to listen.

I use php arguments mostly to get a view block to only show up on certain dynamic url pages. The first time I really used this technique was in one of my previous posts: Related Content with Views 2 in Drupal

Here are a few others with some explanations:

Similar Node Title:

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  return $node->title;
} else {
  return FALSE;
}

To use CCK Field Argument:

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  return $node->field_reference[0][nid];
} else {
  return FALSE;
}

To use the results of any CCK Field to group together you must first know what part of the CCK field you want to use. Check out this post Theming a Node in Drupal...The Easy Way. Notice in the above code the portion

$node->field_reference[0][nid]

This piece of code is what you would change depending on what part of the cck field you wanted to use. In my case I wanted the node id that was placed in the node reference url cck widget.

Even though this is only two arguments, just by changing a small piece you can get it to fit most of your needs.

If there are any arguments that you've found helpful in the past post them in the comment section below.

Make sure and Subscribe to this blog to follow along with other Tips, Tricks, and Tutorials.