I want my categories to have the image above the content and the left column, whilst using 2columns-left.phtml and don't want an image placeholder showing if there's no image. So I need an if statement but not sure how to go about it!

Here's my code so far

<?php $categoryImage = Mage::getModel('catalog/layer')->getCurrentCategory()->getImage(); //Get the file name of the Image stored for the category ?>

<img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$categoryImage  ?>" />

If anyone could help that would be much appreciated.


You can just add an if statement to check for $categoryImage value.

Here's a better way to do it (basically you let Magento create the full URL)

$helper    = $this->helper('catalog/output');
$category  = Mage::getModel('catalog/layer')->getCurrentCategory()

if ($imgUrl = $category->getImageUrl()) {
    $imgHtml = '<img src="'.$imgUrl.'" alt="' . $this->htmlEscape($category->getName()) . '" title="' . $this->htmlEscape($category->getName()) . '" />';
    echo $helper->categoryAttribute($category, $imgHtml, 'image');
| improve this answer | |
  • That worked, thank you so much. I have also tried to upvote the answer but my reputation isn't high enough! – totneschap Aug 9 '17 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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