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... :-(

CommentFileSizeAuthor
#14 view_with_related_terms.txt4.81 KBGiorgosK
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

What is your definition of related terms? I don' know such a name in standard-drupal.

kiko’s picture

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

dawehner’s picture

Status: Postponed (maintainer needs more info) » Active

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.

gagarine’s picture

Hello,

Can i do something similar with filter instead of argument?

Thanks

Dimm’s picture

$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;
}

Faya’s picture

Thanks for this

GiorgosK’s picture

@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 ?

kiko’s picture

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?

kiko’s picture

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

merlinofchaos’s picture

Try this:

$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:

$list = array($argument);
foreach (taxonomy_get_related($argument) as $term) {
  $list[] = $term->tid;
}
$handler->argument = implode('+', $list);
return TRUE; 
kiko’s picture

It works!

Thanks a lot indeed!

dawehner’s picture

Status: Active » Fixed

So this is fixed. Anyone want to write some documentation?

kiko’s picture

GiorgosK’s picture

FileSize
4.81 KB

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 ?

kiko’s picture

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.

Status: Fixed » Closed (fixed)

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

kiko’s picture

Status: Closed (fixed) » Active

I'm changing this issue to open as I'd like to know if there's some way to add this capability to an exposed views filter. I have searched quite a lot but I couldn't find the answer.

Thanks in advance

dawehner’s picture

Status: Active » Fixed

What do you mean with this?

Open a new one, if you can explain what you want.

kiko’s picture

OK. opening a new one

Status: Fixed » Closed (fixed)

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