I have made a block view that shows all nodes with the same terms as the current node.
The code is:

$node = node_load(arg(1));
if ($node) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, 1);
  foreach ($terms as $tid => $term) {
    $tids[] = $tid;
  }
  return implode ("+", $tids);
}
return false;

It works perfectly, but now I wanna show only nodes that have the same term of vocabulary A and vocabulary B. What would I have to add to the code?

Comments

dawehner’s picture

I don't testet it but i think it works

<?php
// allowed Vocabulary-ids
$vids  = array(1, 5);

$node = node_load(arg(1));
if ($node) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, 1);
  foreach ($terms as $tid => $term) {
    if (in_array($term->vid, $vids)) {
      $tids[] = $tid;
    }
  }
  return implode ("+", $tids);
}
return false;
?>
esmerel’s picture

Assigned: rucx » esmerel

This should be evaluated for inclusion in documentation. assigning to myself for that reason.

summit’s picture

Hi,
How about related terms.
Whe you have a vocabulary about geographic information: countries, regions, places and a vocabulary about categories.
How can I get the terms which are having nodes. Say a node camping x in belgium has the terms belgium, antwerp area , and antwerp and the category familycamping.
How can I get on the term page Familycamping show a block of for this example
"familycamping - antwerp"
Thanks a lot for your reply in advance.

greetings,
Martijn

Letharion’s picture

Status: Active » Fixed

There's a function "taxonomy_get_related" which will "Find all term objects related to a given term ID.".
You should be able to use that instead of "taxonomy_node_get_terms_by_vocabulary".

summit’s picture

Hi, Thanks, can I get then say all terms only from a vocabulary on a termpage which is different from the vocabulary of the TID which is shown on the url ? Say the url is taxonomy/term/10 and 10 is a term in vocab 1.
How can I then show a block which shows this term, and a term (familycamping which some nodes also hold from another vocabulary, say 2, which is camping_sorts?

May be you can show a code-exampe please?
Thanks a lot in advance!
greetings, Martijn

Letharion’s picture

Assigned: esmerel » Unassigned
Status: Fixed » Active

I'm sorry, I don't understand your question. What is the relation between the vocabularies? It seems arbitrary.

Letharion’s picture

Status: Active » Postponed (maintainer needs more info)
summit’s picture

Hi, The relation between the vocabularies is are the nodes!
A node has terms from both vocabularies, and when term pages of one vocabulary are shown I would very much show a list of terms from the other vocabulary(ies) attached to the nodes.
Is this more clear please?
Thanks for still considering this.
greetings, Martijn

Letharion’s picture

Assigned: Unassigned » Letharion
Status: Postponed (maintainer needs more info) » Active

Are you still using Views 2.6?
It's also important that you reset the status to active when you've answered previous questions, otherwise the issue is easily forgotten.
I'm assigning this to myself so I will remember to look into this a bit further.

summit’s picture

Version: 6.x-2.6 » 6.x-3.x-dev

Hi, Set the issue to newest 3.x-dev. Thanks for looking into this!
Greetings,
Martijn

iamjon’s picture

Status: Active » Closed (works as designed)

Closing this from a lack of activity.

summit’s picture

Status: Closed (works as designed) » Active

Set to active, didn't have answer from Letharion yet, as stated in #9.
Don't know why closed because of lack of activity. I think Letharion didn't had time to respond yet.
I do not think 3 months is big in Drupal perspective. Eager for your reply still Letharion.
greetings, Martijn

R.Hendel’s picture

Status: Active » Fixed

Hi, is this still an active issue?
I would fix this to clean queue. Please reopen it, if you want to work further on it.
Otherwise it would be closed automatically after two weeks.

R.Hendel’s picture

Issue tags: +dvcs11

forgot to tag with dvcs11...

Status: Fixed » Closed (fixed)
Issue tags: -dvcs11

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