You are here:  » Any way to showing a tempt image instead of the dreaded red cross

Support Forum



Any way to showing a tempt image instead of the dreaded red cross

Submitted by mally on Tue, 2008-05-13 06:14 in

Hi David

I'm wondering if theres a way of showing a standard image instead of the red cross that appears when the image can't be located.

On a large imported feed there could be one or 2 that don't have images or for some reason they do but the image doesn't appear every time.

I've noticed this more on my featured rotater on my home pages like Light Fittings than the actual products page..

Any advice?

Cheers

MAlly

Submitted by support on Tue, 2008-05-13 07:57

Hi Mally,

The only way around this i'm afraid (without complex JavaScript) is to cache all images and serve them through your server, but it can be slow and consumes a lot of bandwidth from your hosting account. I'll dig back through some previous emails as I think one or two people have come up with something involving CSS and a background-image property; but I don't find it on the forum at the moment... will see if I can dig it out...

Cheers,
David.

Submitted by Axonic on Tue, 2008-05-13 14:08

Hi, this is something i would like to get a fix for. I have only just purchased Price Tapestry but I can see the potential; it's excelent code. However, with merchants putting out invalid image URLs this will only put people off buying. So if anyone does have a fix...

Thanks Rob
Thrifty-spider.com

Submitted by mally on Thu, 2008-05-15 16:27

I think to get around this problem there's a way to set a background image that shows if the product image doesn't.

Not sure how to implement it though

Mally

Submitted by support on Fri, 2008-05-16 08:20

Hi All,

The main issue here is detecting that the image has not loaded; because at the point the page is generated all you are sending out is an IMG tag with SRC attribute that is the image URL from the feed.

However, one option seems to be to use the onerror attribute of the IMG tag, although this isn't standards compliant. To try this; locate the IMG code in html/product.php as follows (line 7 in the distribution):

<img width='180' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' />

...and try changing this as follows:

<img width='180' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' onerror="this.src='/images/defaultimg.jpg';" />

Create your default image in the /images/ directory as defaultimg.jpg (or use an alternative name and modify the code above accordingly) and it should load if the main img fails to load.

If this works as expected, to make the same change in html/searchresults.php look for the following code on line 10:

<a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>

...and change this to:

<a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' onerror="this.src='/images/defaultimg.jpg';"/></a>

Cheers,
David.

Submitted by mally on Fri, 2008-05-16 12:41

Hi David

Thanks very much

Can I ask what I need to change for this line of code

      if ($product["image_url"]) { print "<p><a href='".$href."' title='".$product["name"]."'><img class='bdr' width='100' height='140' src='".$product["image_url"]."' alt='".$product["name"]."' title='".$product["name"]."' /></a></p>"; }

Submitted by support on Fri, 2008-05-16 13:57

Hi,

That would be...

      if ($product["image_url"]) { print "<p><a href='".$href."' title='".$product["name"]."'><img class='bdr' width='100' height='140' src='".$product["image_url"]."' alt='".$product["name"]."' title='".$product["name"]."' onerror=\"this.src='/images/defaultimg.jpg';\" /></a></p>"; }

(note the addition of the \ to escape the " character as this is PHP rather than HTML)

Cheers,
David.