By prughj on
I'm stuck. I want to create a block view that lists taxonomy terms related to the nodes taxonomy term. So, my node has a term called "dogs". In the taxonomy interface -> advanced options I assigned two related terms to "dogs". The related terms are "pointer" and "poodle". When I go to the node w/ the term dog, I want to display a sidebar block that shows "pointer" and "poodle".
I know this involves relationships and arguments in views, but I can't figure out the right combination. Is PHP code required?
Thanks!
Comments
If you just want the block to
If you just want the block to show on nodes with the term dogs, no php is required.
Have you added a relationship for Taxonomy: Related terms?
* There are two. Pick the one for terms (not the one for nodes).
* You probably also want to check "Require this relationship".
Have you added an argument for the Node: Nid?
* Under "Action to take if argument is not present:" select the radio that says "Provide default argument" an then select "Node ID from URL".
Have you added a field for Taxonomy: Term?
* Under "Relationship:" select "Related term" (unless you named it something else, but that's the default name for the relationship).
* You probably want to check "Link this field to it's taxonomy term page".
Once you create and enable a block display, a block with links to pointer and poodle will show up on any node with the term dogs.
Views blocks will not read
Views blocks will not read arguments from the URL.
This is a known problem and it mean that you need to write php to extract the argument.
If you follow the instructions above it will seem to work in the preview in the Views page and it will work as a page, but not as a block.
Under "Action to take if argument is not present:" select "Provide default argument" and then select "PHP code"
You will then have to write some php to get the argument from the url to the block, e.g.
I used this code the get the taxonomy term from the url. The path was the form /company/
You should be able to adapt the code for your urls.
I have read that this is not best practice and it would be better to use arg to get the arguments. I do not have an example of this handy but there are probably several in the forum posts if you search.
Why does this work for me? *
Why does this work for me?
* Under "Action to take if argument is not present:" select the radio that says "Provide default argument" an then select "Node ID from URL".
Seriously. Try it. I wouldn't have given the advice unless I'd tried it myself as a block.
My apologies
My apologies
If it works for you then that's good but I spent a day trying to get arguments into Views before I found multuiple forum posts telling me that it would not work without php.
Both Views and the core have been updated since I last did this - maybe it has been fixed.
Hi thanks that works great
Hi thanks that works great for displaying the related terms when viewing a node. Is it possible to do it when viewing a taxonomy term at taxonomy/term/* ?
Ive tried adding a few differant arguments without any success. all help appreciated as its been driving me mad for about 3 years now.
thanks
Thanks- Working now
Thank you for the help, Soren - working great now.