Support forum login

©2006-2008 IAAI Software

Contact Us

No image

Submitted by chrisst1 on Fri, 2006-09-08 15:55.

David
Is there any way to code "if no product image use a default image"

Chris

Submitted by dmorison on Fri, 2006-09-08 17:07.

Hi Chris,

No problem - you'll need to make changes to html/searchresults.php and html/product.php.

In html/searchresults.php, find the following code (starting at line 9):

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

...and change as follows:

          <?php if ($product["image_url"]): ?>
          <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>
          <?php else: ?>
          <img width='80' src='/path/to/default.gif' />
          <?php endif; ?>

And in html/product.php, find the following code, starting at line 6:

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

...and change as follows:

        <?php if ($mainProduct["image_url"]): ?>
          <img width='180' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' />
        <?php else: ?>
          <img width='200' src='/path/to/default.gif' />
        <?php endif; ?>

You might actually want to use a different default image for the small (search results) and large (product page) images; and also note that i've used an absolute path to the image - this is important so that the file can be found whatever page of your site it is on.

Cheers,
David.

Submitted by chrisst1 on Sat, 2006-09-09 10:37.

Thanks Dave super job, should put an end to those red crosses.

Chris
villagefetes

Submitted by pikibou on Sat, 2007-08-18 11:29.

Don't know what's wrong but for me it doesn't work:

Here's my code for product.php

<?php if ($mainProduct["image_url"]): ?>
          <img width='170' onload='JavaScript:if(this.width > 200) this.width=200;' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' />
        <?php else: ?>
          <img width='170' src='/images/noimage.gif' />
        <?php endif; ?>

I have tried almost everything:

- full path to image
- remove onload'javascript ...
- looking at my image on my server
- trying withjpg / gif / ...
- removing url rewrite

In fact, it doesn't seem to recognize those lines:

        <?php else: ?>
          <img width='170' src='/images/noimage.gif' />
        <?php endif; ?>

The same for searchresults.php

Anyone has the solution?

Thanks

Piki

Submitted by pikibou on Sat, 2007-08-18 12:11.

OK, I know why it doesn't work for me / and certainly for you also:

When there's a 404 for the image it shows nothing.

Here's the code I've found on the blog of someone using pricetapestry: targetweb

<?php
$image_to_check = $mainProduct["image_url"];
$html = @getimagesize($image_to_check);
if (!$html){
$productimage = "/images/noimages.gif";
}
else {
$productimage = $mainProduct["image_url"];
}
?>
<p><a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' height='80' src='<?php print $productimage?>' alt='<?php print $product["name"]; ?>' class='image' /></a>

For instance, it checks the size of the image. If no size, then it shows the noimage.gif

--> very nice but I still don't know how to adapt it to product.php

Submitted by dmorison on Sat, 2007-08-18 16:12.

Hi Piki,

The product image is displayed on the product page by the following code on line 7 of html/product.php:

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

You should be able to replace this with similar code to the above mod as follows:

<?php
$image_to_check = $mainProduct["image_url"];
$html = @getimagesize($image_to_check);
if (!$html){
$productimage = "/images/noimages.gif";
}
else {
$productimage = $mainProduct["image_url"];
}
?>
<img width='180' src='<?php print $productimage?>' alt='<?php print $mainProduct["name"]; ?>' />

Hope this helps,
Cheers,
David.

Submitted by pikibou on Sun, 2007-08-19 10:22.

Thanks for the tip!

It works!

Submitted by babyuniverse on Sun, 2007-09-16 10:53.

Hi All,

<?php
$image_to_check 
$mainProduct["image_url"];
$html = @getimagesize($image_to_check);
if (!
$html){
$productimage "/images/noimages.gif";
}
else {
$productimage $mainProduct["image_url"];
}
?>

Works well for product.php - what about searchreuslts.php - still cant get this to work

Submitted by dmorison on Sun, 2007-09-16 11:35.

Hi,

In searchresults.php, you will need to use:

$product["image_url"]

instead of:

$mainProduct["image_url"]

If you're not sure where to use this in searchresults.php, have a look at the code in the first reply in this thread...

Cheers,
David.

Submitted by babyuniverse on Sun, 2007-09-16 12:23.

this is my code in searchresults.php

<?php
$image_to_check = $product["image_url"];
$html = @getimagesize($image_to_check);
if (!$html){
$productimage = "http://www.domain.com/shopping/images/noimage.gif";
}
else {
$productimage = $product["image_url"];
}
?>
<a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>

Submitted by dmorison on Sun, 2007-09-16 12:26.

Hi,

That looks almost correct - I think the only thing missing is you need to replace the image URL in the HTML with your new $productimage variable; like this:

<?php
$image_to_check = $product["image_url"];
$html = @getimagesize($image_to_check);
if (!$html){
$productimage = "http://www.domain.com/shopping/images/noimage.gif";
}
else {
$productimage = $product["image_url"];
}
?>
<a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $productimage?>' alt='<?php print $product["name"]; ?>' /></a>

Hope this helps,
Cheers,
David.

Submitted by babyuniverse on Sun, 2007-09-16 12:32.

thanks again.

This is now working great

Submitted by clare on Wed, 2008-02-27 11:51.

I also find this all works well..except that today my affiliate window feeds, where the image url is from AW server such as
http://images.productserve.com/preview/1525/9956352.jpg

These are all showing as no image when passed through the @getimagesize filter in the code, and so I wonder is it possible that the check image size code, is somehow a problem for some servers? As it only appears to be happening on the AW feeds, where I know the images are there, but are showing in PT as no image using the above code that gets the image size.

Submitted by clare on Wed, 2008-02-27 12:33.

Actually, I have just removed the check image size code and put your original code only, as it is not so often that the image urls are incorrect and return a 404 necessitating that extra getimagesize code. And I found that adding the check image size was also really slowing things down alot.

Submitted by dmorison on Wed, 2008-02-27 12:37.

Hi Clare,

I was going to recommend a similar course of action - the function getimagesize is effectively making a request to fetch all images from the remote server before the page is displayed, so under normal circumstances it's certainly not ideal...!

Cheers,
David.

Submitted by clare on Thu, 2008-02-28 11:58.

Just for future info on this thread, I stumbled across a little dreamweaver extension yesterday that effectively shows a substitute image when an image link is broken, using the DOM on page javascript method.

It can be found at
http://www.linecraft.com/hide_broken/help.php

Submitted by remco on Tue, 2008-03-04 10:32.

David
I,m having the same problem but both solutions dont work for me
What can i do ?

Its driving me nuts

Regards
Remco

Submitted by dmorison on Tue, 2008-03-04 11:14.

Hello Remco,

Are you trying to sort the invalid images issue (where there are image URLs but they don't work - this is quite hard to fix); or to show a default image if there is no image in the feed?

Cheers,
David.

Submitted by remco on Tue, 2008-03-04 12:10.

The last one David
show a default image if there is no image in the feed?

You have my ftp details perhaps you can see whats wrong.

Best Regards
Remco

Submitted by dmorison on Tue, 2008-03-04 12:13.

Hello Remco,

I have still not received any email from you!

Did you reply to the one I sent to you?

Cheers,
David.

Submitted by remco on Tue, 2008-03-04 12:39.

Yes david
very strange
I shall send it from the site its email adres
So i resend it from another new email adres

Best Regards
Remco

Submitted by dmorison on Tue, 2008-03-04 13:22.

Hello Remco,

I received your email now, thanks!

I have made the no image change, and also fixed your modified rewrite problem.

Cheers,
David.

Submitted by nosferatu on Fri, 2008-03-14 18:45.

Hi,

Small change on this code:

!!! Works with html/product.php !!!

<?php
// $image_to_check = $product["image_url"];
$image_to_check = $mainProduct["image_url"];
$html = @getimagesize($image_to_check);
if (!$html){
$productimage = "http://www.site.com/images/noimage.gif";
}
else {
// $productimage = $product["image_url"];
$productimage = $mainProduct["image_url"];
}
?>
<!-- <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $productimage?>' alt='<?php print $product["name"]; ?>' /></a> -->
    <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $productimage?>' alt='<?php print $product["name"]; ?>' /></a>

Submitted by TWDesigns on Tue, 2008-07-29 17:18.

Is there a better way to do this? I used the code mentioned above for searchresults.php and it loads the results really really slow, I'm assuming because it's checking for product image then no image?

Submitted by dmorison on Tue, 2008-07-29 18:24.

Hi,

As this method involves checking EVERY image as a page is loading, if the merchants server is being slow the page load will be significantly affected.

My personal preference is not to register images for merchants who's images are frequently missing or have other regular problems. If you choose to do this, you can display an image not available image if there is no image URL, by modifying html/searchresults.php and changing:

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

to:

          <?php if ($product["image_url"]): ?>
          <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>
          <?php else: ?>
          <img width='80' src='/images/noimage.gif' />
          <?php endif; ?>

Cheers,
David.

--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum

Submitted by Syed on Wed, 2008-08-20 22:32.

Hi David,

The above code works well in searchresults and product.php. In the index page in featured products still broken image appears. I changed to above code in featured.php but still not working. Any idea where it is going wrong?

Thanks,
Syed

Submitted by dmorison on Thu, 2008-08-21 06:28.

Hello Syed,

The relevant part of the original html/featured.php is as follows starting at line 10:

          <?php if ($product["image_url"]): ?>
            <p><a href='<?php print $product["productHREF"]; ?>'><img border='0' height='100' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a></p>
          <?php endif; ?>

Therefore, to modify this as per the above, the following should work:

          <?php if ($product["image_url"]): ?>
            <p><a href='<?php print $product["productHREF"]; ?>'><img border='0' height='100' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a></p>
          <?php else: ?>
            <img height='100' src='/path/to/default.gif' />
          <?php endif; ?>

Cheers,
David.

--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum