Showing the nodes under a taxonomy term AND under the related terms
kiko - October 14, 2009 - 19:46
| Project: | Views |
| Version: | 6.x-2.6 |
| Component: | search data |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | fixed |
Description
Well, that's mostly it. I want to build a view where given a taxonomy, term the content under that taxonomy term and under all of the taxonomy related terms appear. Any help will be welcome!
I can not find a proper way to buil it on my own with the current views, and I'm not a php programmer so... :-(

#1
What is your definition of related terms? I don' know such a name in standard-drupal.
#2
Taxonomy terms have two major extensions: synonyms and related terms. For each term you can define its related terms via e.g. Taxonomy manager.
I have now two terms: term1 and rterm2. I define a relation between term1 and rterm2. I'd like to show all the nodes tagged under term1 or rterm2 when I call to taxonomy/term/term1
K
#3
Ups, i didn't read the issue enough :)
You can use views argument validation php code
<?php$tid = $argument;
$terms = taxonomy_get_related($tid);
foreach ($terms as $term) {
$list[] = $term->tid;
}
$handler->argument = implode(',', $list);
?>
Perhaps you have to rewrite the code to use it for term-names not tids.
#4
Hello,
Can i do something similar with filter instead of argument?
Thanks
#5
<?php$tid = $argument;
$terms = taxonomy_get_related($tid);
foreach ($terms as $term) {
$list[] = $term->tid;
}
if($list){
$handler->argument = implode(',', $list);
return TRUE;
}else{
return FALSE;
}
?>
#6
Thanks for this
#7
@Dimm
where do I put this validation code from #5 ?
EDIT: I suppose you add arguments (from the Views UI)
but for what kind of argument (taxonomy term perhaps ?)
and what settings go in there ?
#8
Hi again
This code almost seem to work, but... What I've done is:
1.- Add a "Taxonomy: Term ID" argument
2.-Validator: PHP Code with the code:
$tid = $argument;$terms = taxonomy_get_related($tid);
foreach ($terms as $term) {
$list[] = $term->tid;
}
$handler->argument = implode(',', $list);
return TRUE;
3.- Save
The code seems to capture all the related arguments, but only the first one is passed to the view. I've tried both, checking and unchecking the option "Allow multiple terms per argument" and "Allow multiple arguments to work together", but nothing happens
Any idea?
#9
Almost solved. The idea is to add a "+" to the implode function, more than a ",". Probably my fault explaining it, I wanted to list everything under a taxonomy term OR its related terms. The code is finally:
$tid = $argument;$terms = taxonomy_get_related($tid);
foreach ($terms as $term) {
$list[] = $term->tid;
}
$handler->argument = implode('+', $list);
return TRUE;
But one problem remains. I can list everything under the related terms, but not those listed under the term itself. Any idea?
Thanks in advance
#10
Try this:
<?php$tid = $argument;
$list = array($tid);
$terms = taxonomy_get_related($tid);
foreach ($terms as $term) {
$list[] = $term->tid;
}
$handler->argument = implode('+', $list);
return TRUE;
?>
You can make this a bit less code like this:
<?php$list = array($argument);
foreach (taxonomy_get_related($argument) as $term) {
$list[] = $term->tid;
}
$handler->argument = implode('+', $list);
return TRUE;
?>
#11
It works!
Thanks a lot indeed!
#12
So this is fixed. Anyone want to write some documentation?
#13
Done: http://drupal.org/node/648462
#14
I have done as described above but when I use exposed (or even non exposed) filter to view nodes of certain term I don't get the related term nodes
here is an export of a very basic view
what am I doing wrong ?
#15
I think the problem is that this method works properly with arguments introduced via URL (e.g. www.example.com/taxonomy/term/%), but not with filters.