Only in IE8, the presence of the following if statement results in no image being displayed, even though the page source is identical in FF, Chrome and IE8. <?php if (!$page) { ?>href="<?php print $node_url?>"><?php }. The if statement simply prevents the href statement from being added if we are in node view. If I remove the if statement, the image appears as expected.

Here is the complete php code folowed by idendical page source from FF and IE8:

<a <?php if (!$page) { ?>href="<?php print $node_url?>"><?php } print theme('imagecache', $field_inline_1_image_width[0]['value'], $field_inline_1_image[0]['filepath'], $node->title, '', array('style' => 'border:'.$field_inline_1_image_border[0]['value'].'px solid #bbb')); ?></a>

FF page source:

<a <img src="http://www.newsite.fillmoregazette.com/sites/default/files/imagecache/640/images/2010/01/22/sports-test-editor-joe-22-01-2010-1648.jpg" alt="test from editor joe" title=""  style="border:1px solid #bbb" width="640" height="480" /></a>

IE8 page source:

<a <img src="http://www.newsite.fillmoregazette.com/sites/default/files/imagecache/640/images/2010/01/22/sports-test-editor-joe-22-01-2010-1648.jpg" alt="test from editor joe" title=""  style="border:1px solid #bbb" width="640" height="480" /></a>

Anyone have a clue as to why the presence of the if statment causes the image to not be displayed in IE8?
Thank you,
Scott

Comments

marcvangend’s picture

Your code produces invalid html, which causes inconsistent behavior across browsers while they are trying to make the best of it. Fix you php by moving the > after the href outside the if statement.

Sc0tt’s picture

..and duh on my part. Must learn to go to bed before brain stops working.

I asked the same question last night in a php forum and got a different approach that works:

<?php>
$image = theme('imagecache', $field_inline_1_image_width[0]['value'], $field_inline_1_image[0]['filepath'], $node->title, '', array('style' => 'border:'.$field_inline_1_image_border[0]['value'].'px solid #bbb'));
 
if (!$page) {
  $image = '<a href="' . $node_url . '">' . $image . '</a>';
}
 
print $image;
?>

Scott

marcvangend’s picture

Or, if you want to use the Drupal API to the max, use the l() function:

$image = theme('imagecache', $field_inline_1_image_width[0]['value'], $field_inline_1_image[0]['filepath'], $node->title, '', array('style' => 'border:'.$field_inline_1_image_border[0]['value'].'px solid #bbb'));

if (!$page) {
  // I don't know what your $node_url variable looks like, but I'm assuming that you have the Node ID available as $nid
  $image = l($image, 'node/'.$nid, array('html' => TRUE));
}

print $image;