Hey guys.
I am well and truly stuck here. I feel this should be a simple script but nothing I write works in any way like it should. I am trying to create a Views Block which will show related content by using an argument to get nodes from the same term as the node currently being viewed. Here's the code I am using...

$node=node_load(arg(1));
    if($node){
    foreach($node->taxonomy as $term){$terms[]=$term->tid;}
    return implode('+',$terms);
    }else {return;}

And it works perfect, but what I wish to do is make that code select a specific vocabulary, e,g. the one with ID "12"

Simple enough? I've been working on this all day and am now stuck. I'll be grateful for any info you can provide.

Thanks in advance.

Comments

jcmc’s picture

Hello,
perhaps help this

foreach($node->taxonomy as $term){
if ($term->vid == 12) {
$terms[]=$term->tid;
}
}

the vid is the id from parent vocabulary

darklight’s picture

Hi there.
I already tried this sort of thing. Nevertheless I tried it again, and regardless of how I re-work it, I still don't get what I want. I tried using bits out of this code to merge with my current code and still no good.

Surely this is not impossible to do.

I simply want to return nodes "with the same tags" from WITHIN the "same category". Both using the Taxonomy System.

Thanks.

darklight’s picture

Hey guys. Nevermind, I fixed it! I am using two Arguments both with "work together" option enabled. In one I have the PHP:

$node=node_load(arg(1));
if($node->taxonomy){
  foreach($node->taxonomy as $term){
    if ($term->vid == 12) {
      $terms[]=$term->tid;
    }
  }
}
if ($terms) { return implode('+',$terms); }

and in the other I have:

$node=node_load(arg(1));
if($node->taxonomy){
  foreach($node->taxonomy as $term){
    if ($term->vid == 19) {
      $terms[]=$term->tid;
    }
  }
}
if ($terms) { return implode('+',$terms); }

These work perfect. Although, any upgrades are welcomed, e.g. Merging all of this into just one argument.