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

dawehner’s picture

Status: Active » Fixed

It 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Andy Feind’s picture

Status: Closed (fixed) » Active

What 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

dawehner’s picture

Status: Active » Fixed

If it's part of the url you can always use arg() .
Please take care that you don't hijack issues with probably other content.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.