This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template
block if you have followed my answer in your previous thread.
Let us look what is gone wrong here. The error says you are calling getImageUrl()
on a non-object. This means $_category
is a non-object. Now as per your template code, $_category
is defined like this.
$_category = $this->getCurrentCategory();
This means you are expecting $_category
should hold the current category. But what really happened is it holds a NULL
value since $this->getCurrentCategory()
returns nothing. A quick solution for this is,
$_category = Mage::registry('current_category');
if ($_category) {
//then show your banner code.
} else {
//do nothing
}
Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template
block.
Let me know your feedback after try this.
#EDIT
EDIT
I tested below code and it works well for me.
<?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; ?>