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

.carey’s picture

I found this on Drupal sometime ago. It's to be placed in your page.tpl.php file.

<?php if(arg(0)=='taxonomy' & arg(1)=='term' & arg(2)== '64'): ?>

Disclaimer info here.

<?php endif; ?>

FYI: I know it works for 4.7 but have not tried it for 5.x.

Hope this helps in some way.

dman’s picture

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.php between the $node->content and the $links, I inserted

  $vid = 4; # vocabulary ID to select from.
  $conditions =  taxonomy_node_get_terms_by_vocabulary($node->nid, $vid);
  foreach((array)$conditions as $condition){
    print('<div class="condition '. preg_replace('/[^a-z]+/', '-', strtolower($condition->name)) .'">'. $condition->name .'</div>');
  }

The '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

    <div class="condition replica">This item has been built as a replica and is intended for display purposes only and as such does not meet any internationally recognised safety standards.</div>
    

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/

BradM’s picture

Thanks for the pointer, but so far I can't get it to work. Here's what I have:

  $vid = 65; 
  $conditions =  taxonomy_node_get_terms_by_vocabulary($node->nid, $vid);
  foreach((array)$conditions as $condition){
    print $disclaimer;
  }

($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.

dman’s picture

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:

  $conditions =  taxonomy_node_get_terms($node->nid);
  foreach((array)$conditions as $condition){
    if($condition->tid == 65){
      print $disclaimer;
    }
  }

But that's short-sighted code. Should work tho.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

BradM’s picture

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?

dman’s picture

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/

holydrupal’s picture

How about a solution like this:
http://drupal.org/node/151447

using an if tag an assigning a taxonomy for those contents/pages.