By BradM on
Hey all, I've been fiddling with this for a while but haven't come up with a solution yet. I have articles and news items that are all 'story' nodes, and I want a specific disclaimer to be shown when viewing an article (term 64), but not a news item. Therefore adding code to filter for node type won't work; can this be done by taxonomy term instead?
I was trying different things like:
$node->term == 64
$node->taxo_id == 64
$terms == 64
$taxo_id == 64
But none of these produced the message within the article. Any ideas?
Comments
Maybe something like this...
I found this on Drupal sometime ago. It's to be placed in your page.tpl.php file.
FYI: I know it works for 4.7 but have not tried it for 5.x.
Hope this helps in some way.
here you go
Here's what I just did for a product shop which displays 'replicas', 'working order' and 'certified' items alongside each other. Each type of 'condition' needed a full disclaimer on the purchase screen.
The status was tagged using taxonomy, (vocab 'Condition' - #4 ) and the disclaimer was entered as the description of the respective term.
In my node (page) template
node-product.tpl.phpbetween the $node->content and the $links, I insertedThe 'class' addition isn't strictly neccessary, but added semantic sugar for me.
The foreach (it's always only one) was just bulletproofing the code against unknown requirements where there could be none or many tags in the 'condition' vocabulary.
I end up with
For the teaser version I did something similar, but only displayed the
$condition->name(wrapping the appropriate chunk in
if($teaser){}).dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks for the pointer, but
Thanks for the pointer, but so far I can't get it to work. Here's what I have:
($disclaimer is defined at the top of my node.tpl.php file)
I actually have three different terms I'm attempting to check, but for now I'm just testing them 1-by-1. So far no disclaimer shows up for any of them.
You have 65 <b>vocabularies</b>?
You have 65 vocabularies?
$vid is for vocabulary.
I suspect 65 is your $tid - term ID - within that vocabulary.
If you're not doing it my dynamic method and really want to hard-code both the terms and the text:
But that's short-sighted code. Should work tho.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks, that did work. I'm
Thanks, that did work. I'm very new to Drupal and php, and by your comments I'm guessing this isn't the best way to code it?
With my modifications, I ended up with:
if(($condition->tid == 63 || $condition->tid == 64 || $condition->tid == 65 || $node->type == 'book') && $page != 0) {
Is that too much extra work for the system to do?
it's fine.
It's no extra work for the system at all. Your version will certainly work just fine.
I just prefer to place those settings in a place where the disclaimer - and the choice of which terms need it - into the Drupal UI rather than embedded in your php code.
eg, my way you would then add the 'disclaimer' text in /admin/content/taxonomy/edit/term/64
... I guess it would miss out on your $type=='book' option that way though. TMTOWTDI.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
How about a solution like
How about a solution like this:
http://drupal.org/node/151447
using an if tag an assigning a taxonomy for those contents/pages.