1

I am using template phtml added php code. this call from static block.Url and link works fine but It's not view any sub category image. I want to show sub category images.



$category = Mage::getModel('catalog/category')->load(12);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0){     
  foreach($subcategories as $subcategory) { ?>       
  •  <a class="product-image" href="<?php echo $subcategory->getURL(); ?>" > 
                       
    
       <img alt="" src="<?php echo $subcategory->getImageUrl(); ?>" />                               
     </a>
                      
       <a href="<?php echo $subcategory->getURL(); ?>" > <?php   echo $subcategory->getName(); ?> </a>
                    
                  
          <?php echo '</div>' ?>
          
        
    
  • 2
    0

    Please replace below code

    <img alt="" src="<?php echo $subcategory->getImageUrl(); ?>" />
    

    to

    <?php $mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>
    <img alt="" src="<?php echo $mediaurl."catalog/category/".$subcategory->getImageUrl(); ?>" /> 
    
    5
    • After change your code inspect browser show location "domainame.com/media/catalog/category" .this can't acess my sub category images. – junaidh Jun 27 '20 at 12:27
    • change getImageUrl() to getImage() – Ishvar Patel Jun 27 '20 at 12:42
    • getImage() isn't also effect any changes – junaidh Jun 27 '20 at 12:54
    • I added your code with manually image show properlly <img alt="" src="<?php echo $mediaurl."catalog/category/".'iphone-pro-max_1.jpg'; ?>" /> .I want to programatically view image.This category location image access.It will work – junaidh Jun 27 '20 at 13:22
    • Please give me website detials I will check it – Ishvar Patel Jun 27 '20 at 13:28

    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.