Hello,
I'm facing a bit of a problem trying to selectively list out taxonomy terms as links, based on whether the nodes they are attached to have a term from another vocabulary applied.
I think I may only be able to do this programmatically which shivers my timbers as I'm a bit lame at PHP. So I thought I would ask in here if I'm on the right tack or not, before embarking on writing the code.
Heres the scenario:
I have a taxonomy vocabulary called Grommets which lists all the types of grommets we have. Lets say there are four terms there: rubber, plastic, silicone & latex.
I have another vocabulary called Color which has two terms: black and red.
I have a content type called Product-Grommet which is tagged with the above two vocabularies, only one term from Grommets vocabulary for each node. But can be multiple terms from Color vocabulary.
Here's a little table of the thing:
Product-Grommet (nodes) |
Grommets (taxonomy vocab) |
Color (taxonomy vocab) |
| 1_basic_grommet | rubber | red |
| 2_extra_grommet | silicone | black |
| 3_delux_grommet | plastic | red, black |
Now, I would like to have a page where I list (as links) the taxonomy terms (not the nodes) for red Grommets and another page where I list the terms for black Grommets. If there are no rubber grommets which are red, that link ("rubber") should not be displayed
Unfortunately I can't do this with taxonomy and views alone.
It would require checking through all Product-Grommet nodes tagged with a term from Grommets to see if they are also tagged with Color=red.
Pseudo-code example
Links_array = our empty array which will hold the taxonomy links we are going to collect. Structure: Linktext, TID pairs.
Color_checkstring = "red" - the color we are looking for to build our red grommets link page
Node_list_array = Make a list of all nodes tagged with Grommets vocabulary AND with Color = Color_checkstring
For each Node_list_array
Get Grommets term for this node and add it to our Links_array, checking first to see if it's already there, to prevent duplicate links.
Next
Print the Links_array elements as link to TIDS
I'm also not sure if this should be a module or a views custom field with php code, or indeed if somebody has already done something similar. I'm also open to any alternative ideas on how to achieve this functionality.
All the best,
Nick