Hi, I have the following situation:

1. Image field has a default image assigned.
2. Most of the nodes have their own images, but some of them don't have them and they can only use the default image.
3. Image field is printed in node.tpl.php with the following code:

<?php if ($field_image): ?><?php print render($content['field_image']); ?><?php print $node->field_image['und'][0]['title']; ?><?php endif; ?>

The problem is that this always prints the image - either node's own image or, if it doesn't have its own image, the default image. How can I print it only if it has its own image (it should ignore default image in this case)?

Comments

Snehal Brahmbhatt’s picture

Hi 1mundus,

When node's default image loads, there is one parameter which can be used
"is_default = 1", I have added one more condition in your code and it
will fulfill your requirement.

<?php if ($field_image <strong>&& !isset($node->field_image1['und'][0]['is_default'])</strong>): ?><?php print render($content['field_image']); ?><?php print $node->field_image['und'][0]['title']; ?><?php endif; ?>

Let me know if you face any query.

Thanks,
Snehal Brahmbhatt | AddWeb Solution
Email: contact@addwebsolution.com

sanjay.soni’s picture

You can also do the same work at preprocess level using template.php
Try to hide picture Theme_preprocess_node hook.

Version: 7.34 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.