Is there any way to get a list of Nodes in a certain taxonomy?

I would like to do this with views, but the problem is I have to create a block for each Term in the vocabulary, and approximately 80 (and growing). Something similar to the "taxonomy_term" view, but as a block and dynamically.

So if anyone can gimme instructions/ recommendations on how to approach this please do. Any and all suggestions will be greatly appreciated.

Thank you in advance

Comments

nevets’s picture

You can probably due want you want, the question is how would you want to determine which term id to show in the block?

spyke100’s picture

Pick the first Term in the Current node and show all other "nodes" in this term.

nevets’s picture

Ok, make a new view and have it list content in the way you want, I used a view with a style of unformatted and row style of fields and pick 'Node: Title' as the only field (I also cleared the label for the field). I then added two arguments

Argument 1: Node: Nid

  • Title: empty
  • Action to take if argument is not present: Provide default argument
  • Default argument type: Node ID from URL
  • Validator: Node
  • Types: (pick the types you want the block to display for)
  • Check "Exclude the argument"

Argument 2: Taxonomy: Term

  • Title: "Other content tagged %2"
  • Action to take if argument is not present: Provide default argument
  • Default argument type: PHP code
  • PHP argument code:
    $node = node_load(arg(1));
    if ( is_array($node->taxonomy) ) {
       // Get the first term
       $term =  array_shift($node->taxonomy);
       return $term->name;
    }
    return;
    

Add a block display. save the view and add the block to the region where you want it to display.

spyke100’s picture

Once again, thank you very much. It worked.

stellarvisions’s picture

I've had a bit of a block using arguments in Views 2 and this post made much clear to me, and I am using the insights with great success!

thank you nevets, very very helpful

---
Stella Gassaway
principal

STELLARViSIONs : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.

---
Stella Gassaway
principal

stellarvisions : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.

stellarvisions’s picture

This works great for me but for my purposes I would like to show all nodes, including the current one, if that is possible.

I tried to see if I could figure out how to do this but it is beyond me I'm afraid. Any help greatly appreciated.

thanks!

---
Stella Gassaway
principal

STELLARViSIONs : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.

---
Stella Gassaway
principal

stellarvisions : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.

nevets’s picture

I think all you need to do is uncheck "Exclude the argument"

stellarvisions’s picture

I thought that as well, but when I do it the rest of the list disappears and i only have the current node listed. hmmm.

any other info you need?

---
Stella Gassaway
principal

STELLARViSIONs : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced to reflect core values.

---
Stella Gassaway
principal

stellarvisions : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.

nevets’s picture

Ok,remove argument 1 and change the PHP for argument 2 to

if ( arg(0) == 'node' &&  is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  if ( is_array($node->taxonomy) ) {
     // Get the first term
     $term =  array_shift($node->taxonomy);
     return $term->name;
  }
}
return;

If you want this for only one content type try

if ( arg(0) == 'node' &&  is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  // Change  YOUR_TYPE to the content type you want
  if ( $node->type == 'YOUR_TYPE' && is_array($node->taxonomy) ) {
     // Get the first term
     $term =  array_shift($node->taxonomy);
     return $term->name;
  }
}
return;
stellarvisions’s picture

worked like a charm!

many thanks.

---
Stella Gassaway

---
Stella Gassaway
principal

stellarvisions : communication architects
http://www.stellarvisions.com

We design culture-driven tools™
that shape how information is
organized, displayed, shared, and
experienced.