I have to create a website that allows for a "new" tag to be floated above certain pictures that have the specific taxonomy term of "new". I created a view for the "new" where I added an empty div below the image and then floated it above the image and added the actual "new" image with CSS. This is what it looks like For the "new" node.tpl.php the code looks like this:
<article class="node-<?php print $node->nid; ?>
<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div id="new-intro"><?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
<?php print render($content['links']); ?></div>
<?php print render($content['comments']); ?>
</article>
The id="new-intro" is the code that adds the background image to the empty div and places it above the product image. So what I need is a code that automatically adds the id="new-intro" based on whether the product has the taxonomy term of "new" I've found quite a few PHP samples but my knowledge is fairly limited and so I'm not sure that I'm editing them properly. Can any one point me in the right direction?? Thanks so much!!
Edit: So using the code below my code looks like this: template.php:
function hayfield_preprocess_node(&$vars) {
$node = $vars['node'];
$vars['new_introduction'] = FALSE;
if ($terms = field_get_items('node', $node, $field_new_introduction)) {
foreach ($terms as $term) {
if ($term['tid'] == 'new') {
$vars['new_introduction'] = t('!published' == TRUE');
}
}
}
}
and the node code looks like this:
<article class="node-<?php print $node->nid; ?> <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div <?php if ($new_introduction): ?> <?php print 'class="new-intro"' ?> <?php endif; ?>><?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
<?php print render($content['links']); ?></div>
<?php print render($content['comments']); ?>
</article>
But it's throwing major errors :
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /Users/Candace Morgan 2/Sites/hayfield/sites/all/themes/hayfield/template.php on line 33
(it doesn't like my argument in the last line of the template.php)
Fatal error: Cannot access empty property in /Users/Candace Morgan 2/Sites/hayfield/modules/field/field.module on line 936
the Content type is product_display, the field in the content type is field_new_introduction, the taxonomy vocabulary name is new and the taxonomy term name I want to reference is New Introduction.
I'm yanking my hair out on this one!! Thank you for any help you can give me!!
t('!published' == TRUE');
should probably bet('!published == TRUE');
. Even in that case, there is no need to pass tot()
a string you are using just for debugging, as it will never translate, for the fact nobody is providing a translation for it that is available on http://localize.drupal.org.