-1

I'm using Opencart to build a site. You can add banners to all categories.

I want to have the banner show and the text which is currently there by default hide... but if there is no banner show the default text again.

How could I do this in PHP? What I have tried so far:

<h1><?php echo $heading_title; ?></h1>
<div class="category-info">
<?php if ($thumb) { ?>
    <div class="image"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" /></div>
<?php } else {?> 
    <p><?php echo $description; ?></p>
<?php } ?>
</div>

Thanks!

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Joe Consterdine
  • 1,035
  • 1
  • 18
  • 37

1 Answers1

1

Find following code at catalog/view/theme/YOUR_THEME_NAME/product/category.tpl

<h2><?php echo $heading_title; ?></h2>
  <?php if ($thumb || $description) { ?>
  <div class="row">
    <?php if ($thumb) { ?>
    <div class="col-sm-2">
      <img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" title="<?php echo $heading_title; ?>" class="img-thumbnail" />
    </div>
    <?php } ?>
    <?php if ($description) { ?>
    <div class="col-sm-10"><?php echo $description; ?></div>
    <?php } ?>
  </div>
  <hr>
  <?php } ?>

In the above code heading title (or category name) is shown and checks whether category thumb image or description of that category is inserted or not. If only they are inserted then they are shown. I have twisted to get your requirement,

Now replace with following code:

 <div class="row">
    <?php if ($thumb) { ?>
    <div class="col-sm-2">
      <img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" title="<?php echo $heading_title; ?>" class="img-thumbnail" />
    </div>
    <?php }else{ ?>
    <h2><?php echo $heading_title; ?></h2>
    <?php } ?>
    <?php if ($description) { ?>
    <div class="col-sm-10"><?php echo $description; ?></div>
    <?php } ?>
  </div>
  <hr>

So now as per the above code, category image is shown if there is category image nor category name is shown. If description is inserted then description is shown.

Rupak Nepali
  • 719
  • 1
  • 6
  • 13
  • Hi Rupak, thanks for the reply. Isn't ($thumb) targeting all thumbnails on the page? I only want the category banner to be selected not all the other images on the page. Thanks! – Joe Consterdine Sep 28 '15 at 09:26
  • Hi Joe, $thumb is for category banner. For category products' image you can see **$product['thumb']** – Rupak Nepali Sep 28 '15 at 18:03