-2

in my opencart I have image in products category page. If I have set image in category show in category if I haven't set image show onather one.

    <?php if ($thumb) { ?>
  <div class="category-img" style="background: url('<?php echo $thumb; ?>') no-repeat;"></div>
<?php }else{ ?>
  <div class="category-img" style="background: url(image/catalog/category/default-thum.jpg) 50% 50% no-repeat;"></div>
<?php } ?>

I want to modify code.

If I have set image then show image, else if No showing.

Can someone tell me how to modify code?

1 Answers1

1

Use ternary operator .Check this code:

  <div class="category-img" style="background: url('<?php echo ($thumb ?: 'image/catalog/category/default-thum.jpg'); ?>') 50% 50% no-repeat;"></div>

http://php.net/manual/en/language.operators.comparison.php

Bhunesh Satpada
  • 770
  • 1
  • 6
  • 19