Magento : Category images from resized folder

My Study

Generally magento category images call from media/catalog/category. But some time we want resize and want call from resized folder.

So for that make static block

{{block type=”catalog/navigation” name=”catalog.categories” template=”catalog/navigation/category_listing.phtml”}} and code for category_listing.phtml is below.


<?php $_helper = Mage::helper(‘catalog/category’) ?>
<?php $_categories1 = $this->getCurrentChildCategories(); ?>
<?php $_collectionSize = $_categories1->count() ;?>
<?php $_columnCount = 4; ?>
<?php $i=0;  foreach($_categories1 as $categories):  ?>
<?php if ($i++%4==0): ?>
<?php endif ?>
$categories = Mage::getModel(‘catalog/category’)->load($categories->getId());
$actualimageUrl = $categories->getImageUrl();

$actualimageName = substr(strrchr($actualimageUrl,”/”),1);
$imageUrl = Mage::getBaseDir(‘media’).DS.”catalog”.DS.”category”.DS.$actualimageName;
$imageResized = Mage::getBaseDir(‘media’).DS.”catalog”.DS.”category”.DS.”resized”.DS.$actualimageName;

if (!file_exists($imageResized)&&file_exists($imageUrl)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->resize(200, 200);
<a href=”<?php echo $categories->getUrl(); ?>”>
<img src=”<?php echo Mage::getBaseUrl(‘media’).”catalog/category/resized/”.$actualimageName; ?>” /></a>
<a href=”<?php echo $categories->getUrl(); ?>”><h1><?php echo $categories->getname(); ?></h1></a>
<?php if ($i%4==0 || $i==$_collectionSize): ?>
<?php endif ?>
<?php endforeach; ?>
decorateGeneric($$(‘ul.products-grid’), [‘odd’,’even’,’first’,’last’])

View original post


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s