2

All of my nodes of a certain content type are given a category by assigning a taxonomy term. I would only like to add the flag, "My Fruits" if the content has the term "Fruit" assigned to it.

So far I've attempted using a views PHP field to add the flag:

This works to simply print the flag:

<?php 
print flag_create_link("basket_01_t01_fruit", $row->nid);
?> 

But this, I'm not able to get working:

<?php 
if ($row->field_item_produce_type == '3') {
print flag_create_link("basket_01_t01_fruit", $row->nid);
}
?> 

Any ideas would be appreciated.

3

You could achieve this easily using views without using views php field. More specifically you can create a view of content with an EVA (entity views attach) field display where you will add the flag link field and attach it to the nodes of that content type. Just make sure to:

  1. Add a contextual filter of Content:Nid
  2. Add a relationship of "Content:Taxonomy terms on node"
  3. Also add a "Flags: Node flag" relationship (uncheck the include flagged content only checkbox)
  4. Add a filter "Content type:...your content type which nodes will have the flag link
  5. Add a filter "Taxonomy term: Term ID" that will equal to the tid of the "fruit" term.

After that you can easily choose how to display this eva field on your nodes using Display suite.

| improve this answer | |
  • Thanks, after some effort I was able to accomplish this with your suggestion. – dgdoing May 17 '13 at 22:37
  • Cheers. Glad to help. – Billy May 18 '13 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.