Skip to content

Commit

Permalink
Frontend: Added width/height HTML attributes to category main image
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Jan 17, 2025
1 parent 550eda4 commit fc2a352
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
16 changes: 13 additions & 3 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,21 @@ public function formatUrlKey($str, $locale = null)
*/
public function getImageUrl()
{
$url = false;
if ($image = $this->getImage()) {
$url = Mage::getBaseUrl('media') . 'catalog/category/' . $image;
return Mage::getBaseUrl('media') . 'catalog/category/' . $image;
}
return $url;
return '';
}

/**
* @return string
*/
public function getImagePath()
{
if ($image = $this->getImage()) {
return Mage::getBaseDir('media') . '/catalog/category/' . $image;
}
return '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
* @package base_default
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
* @copyright Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
* @copyright Copyright (c) 2024 Maho (https://mahocommerce.com)
* @copyright Copyright (c) 2024-2025 Maho (https://mahocommerce.com)
* @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* Category view template
*
* @var Mage_Catalog_Block_Category_View $this
*/

/** @var Mage_Catalog_Block_Category_View $this */
?>
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
$imageWidth = $imageHeight = '';
$imagePath = $_category->getImagePath();
$imageSize = getimagesize($imagePath);
if ($imageSize) {
$imageWidth = $imageSize[0];
$imageHeight = $imageSize[1];
}
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" width="' . $imageWidth . '" height="' . $imageHeight . '" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
Expand Down
1 change: 1 addition & 0 deletions public/skin/frontend/rwd/default/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,7 @@ p.product-name a:hover {
.category-image img {
width: 100%;
max-width: 100%;
height: auto;
}
.category-image img:hidden {
display: none;
Expand Down

0 comments on commit fc2a352

Please sign in to comment.