2

I have the following code that displays my category banner image:

          <?php
            $_helper    = $this->helper('catalog/output');
            $_category  = Mage::registry('current_category');
            $_imgHtml   = '';
            if ($_imgUrl = $_category->getImageUrl()) {
                $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
                $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
            }
            ?>

          <?php if($_imgUrl): ?>
          <?php echo $_imgHtml ?>
          <?php endif; ?>

I'd like to adapt the code, so that if no category banner exists an alternative banner is displayed. The alternative banner is stored in a static block called 'alternative_cat_banner'.

Can anyone suggest an edit to the code above to achieve this please?

1 Answer 1

3

Try this...

<?php if($_imgUrl) { ?>
<!-- Category has Image uploaded -->
<?php echo $_imgHtml ?>
<?php }else{ ?>
<!-- Category has NO Image uploaded, show static block named alternative_cat_banner -->
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('alternative_cat_banner')->toHtml() ?>
<?php }?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.