Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Category image only to show if image uploaded


000---000

Recommended Posts

Posted

Can someone advise me how I can have the category image box only show when an image has been uploaded. ie If there's no image then a blank box +red X does not appear. I think I'm after an "if" command. The current code which shows the image is as follows (this also shows a blank box if no image is available):

 

<?php echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

 

Can anyone advise of the "if" coding I need please. I also need this for a text description too, but if this is answered I should be able to work the rest out.

 

Thanks.

 

Matt

oscommerce_community_forums.gif
Posted

Something like this:

 

<?php
 if ($image_size = @getimagesize(DIR_WS_IMAGES . $category['categories_image'])) {
echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
 }
 else {
/* 
insert code for no image here
*/
 }
?>

BACKUP BEFORE EDITING.

 

You break it - You bought it...

:blush:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Posted
Something like this:

 

<?php
 if ($image_size = @getimagesize(DIR_WS_IMAGES . $category['categories_image'])) {
echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
 }
 else {
/* 
insert code for no image here
*/
 }
?>

BACKUP BEFORE EDITING.

 

You break it - You bought it...

:blush:

 

Thanks, that's exactly what I needed. Just a check though, this isn't how I would have thought it best done (but am keeping it). Am I right in thinking that this works by checking if the image has a size/dimensions and if not then the result is the "no image code"? Many thanks. Matt

oscommerce_community_forums.gif
Posted

Here's another option.

 

When you create a category, upload the image pixel_trans.gif, assuming you don't have a picture for that specific category. You can find this image inside the images folder of an oscommerce install.

 

It's a very small image(1x1). It's also transparent that it blends very well in the background.

It's virtually invisible.

 

This way you don't get the empty box with a red mark.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...