Kriuchko
1/9/2019 - 9:17 AM

Get subcategories

Magento 1 get category childrens

<?php
    $nav_class = new Mage_Catalog_Block_Navigation;
    $webshop_category_id = Mage::getModel('core/variable')->loadByCode('webshop_category_id')->getValue('html');
    if(!empty($webshop_category_id)){
        $webshop = Mage::getModel('catalog/category')->load($webshop_category_id);
        $childrens = $webshop->getResource()->getChildren($webshop, true);
    }
    if($childrens && count($childrens)):
?>
  <form action="#" class="filter-form custom-form">
    <fieldset>
      <select onchange="setLocation(this.value)">
        <?php foreach ($childrens as $children): $children = Mage::getModel('catalog/category')->load($children);  ?>
          <?php if ($children->getIsActive() && $children->getIncludeInMenu()): ?>
              <option value="<?php print $nav_class->getCategoryUrl($children);?>" <?php if ($nav_class->isCategoryActive($children)) echo ' selected="selected"';?>>
                  <?php print $this->htmlEscape($children->getName());?>
              </option>
          <?php endif;?>                                          
        <?php endforeach;?>        
      </select>
    </fieldset>
  </form>
<?php endif; ?>
<?php
$flag = 0;

$subcats = $_category->getChildrenCategories(); 
if(!empty($subcats)) : $flag = 1; 
?>
<div class="category-products">
  <ol class="listing-type-grid catalog-listing">
    <?php
        foreach($subcats as $subCatid)
        { 
          $_category = Mage::getModel('catalog/category')->load($subCatid->getId());
          if($_category->getIsActive())
          {
            $caturl = $_category->getURL();
            $catname = $_category->getName();

            if($_category->getImageUrl())
            {
              $catimg = $_category->getImageUrl();
            }
            echo ' <li class="item">';
            if(!empty($catimg)){
                echo '<div class="product-image">
                      <a href="'.$caturl.'">
                        <span class="image-holder">
                          <img src="'.$catimg.'" width="179" height="112" alt="image description" />
                        </span>
                      </a>
                    </div>';
            }
                    
            echo '<h3><a href="'.$caturl.'">'.$catname.'</a></h3>
                  </li>';
          }
        }

    ?>
  </ol>
</div>
<?php endif; ?>