How do I use the list of of taxonomy terms of the current node in a view block as filter?

Also how do I create the view in the first place using the information?

Comments

merlinofchaos’s picture

Status: Active » Closed (fixed)

You'll have to use the PHP Code argument default setting and extract the taxonomy with PHP. Sorry, I don't have the time to tell you how to do this; there's LOTS in the snippets and you can probably find some support in the forums for at least extracting the terms, but that's beyond the scope of what I'm prepared to spend time on.

chandrabhan’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

I have found this code snippet.

$tids = '';
if($type == 'block' && arg(0) == 'node' && is_numeric(arg(1) ) ){
$vid = 2; // this is the vocabulary id to search through...
$terms = taxonomy_node_get_terms_by_vocabulary(arg(1), $vid);
foreach($terms as $term){
$tids[] = $term->tid;
}
$tids = implode('+', $tids);
}
return array($tids);

It says that i need to provide this using 'Argumrnt handling code' field in my view. But i cant seem to find that in views 2.0. Could you please help?

merlinofchaos’s picture

In the argument settings, set the default action to 'Provide default argument'.

Then set the argument default to PHP code.

One difference between Views 1 and Views 2 is that in Views 1, you d set all the arguments at once. In Views 2, however, each argument is its own PHP snippet. So instead of returning an array, as above, you'll return just the argument.

Changing return array($tids) into return $tids should do the trick.

chandrabhan’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
okday’s picture

Hi,

i've tried this code but is doesn't work..

$tids = '';
if($type == 'block' && arg(0) == 'node' && is_numeric(arg(1) ) ){
$vid = 2; // this is the vocabulary id to search through...
$terms = taxonomy_node_get_terms_by_vocabulary(arg(1), $vid);
foreach($terms as $term){
$tids[] = $term->tid;
}
$tids = implode('+', $tids);
}
return $tids;

I have changed my VID to the correct vocaburary id.

someone have a new code?

thanks.

jastraat’s picture