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.
Comments
Views arguments for blocks
Nice writeup! I've found that one handy use of php in views arguments is to get around the issue where url arguments aren't available to blocks.
http://www.centurionwebdev.com/content/using-arguments-views-2
fg
I'm thankful to the one who wrote this passage. I always read and write this style of articles. youtube Also, as a daily writer, I present my respects to the
In my opinion, people should research first and write then.
Regards.
Similar argument for revisions?
Great post! This has gotten me close to what I am trying to achieve, but not quite there yet.... I'm trying to create a view that pulls data from a field within a unpublished node revision, so that it can be a part of the node's preview before being approved by a moderator.
Currently at best, it only seems to show the published node's cck field data in the preview.
Do you know how I may be able to use a similar approach as the above, to accomplish this? Both the node and the revision #s would be different with each revision viewed.
Hi Guys i hope you can help with suggestions.
I want to display a block on my organisations node which will display news from the news node.
Now the news must be of the taxonmy term from the news vocabulary which = the title of the organisation node.
I hope thats clear and you can help me work this in views.
Thanks much for this. Finding
Thanks much for this. Finding concrete examples of how to implement arguments has proven to be strangely hard.
Post new comment