Hi,
I am trying to display a view with a contextual filter that returns either the NID from url if the current node is of type, let's say X, or the value "all". I thought the best way to achieve this is to use the php code as default value for the contextual filter and to write something like:
$currnode=$node;
if ($currnode->$type=="X"){
return $currnode->$nid;
}
else{
return "all";
}
However, it doesn't work as I do not know how to get te $nid of the current node. It seems that the object $node isn't available anymore form views. Could anyone help please?
Thanks in advance
Comments
Comment #1
dawehnerIt was never availible at that point!
You could use $node = menu_get_object();
But in general you could also use $node from current url and filter out the node type directly.
Comment #3
Andy Feind commentedWhat about getting the $node->nid in listings?
$node = menu_get_object(); works fine, if you are on a node page.
However, I'd like to use the same view (lists the first five comments of a node) on the first node teaser in a taxonomy node listing.
Any ideas? Thanx!
Drupal 7.7
Views 7.x-3.0-rc1
Comment #4
dawehnerIf it's part of the url you can always use arg() .
Please take care that you don't hijack issues with probably other content.