Created
June 20, 2016 17:49
-
-
Save rodrigowebjump/47fc1acc94c57baf5073cc36f81f8ce2 to your computer and use it in GitHub Desktop.
Magento show subcategories of current category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$_categoryModel = Mage::getSingleton('catalog/layer')->getCurrentCategory(); | |
$_categories = $_categoryModel->getCollection() | |
->addAttributeToSelect(array('name', 'thumbnail', 'image', 'description',)) | |
->addAttributeToFilter('is_active', 1) | |
->addIdFilter($_categoryModel->getChildren()) | |
; | |
if(empty($_categories)){ | |
return; | |
} | |
$_span = 'span4'; | |
$_grid_pro = Mage::getStoreConfig('themeoptions/themeoptions_config/grid_product'); | |
if ( !$_grid_pro ) { $_grid_pro = 3; } | |
switch ($_grid_pro) | |
{ | |
case 2: | |
$_span = 'span6'; | |
break; | |
case 3: | |
$_span = 'span4'; | |
break; | |
case 4: | |
$_span = 'span3'; | |
break; | |
} | |
$_collectionSize = $_categories->count(); | |
$_columnCount = $_grid_pro; //$this->getColumnCount(); | |
?> | |
<?php $i=0; foreach ($_categories as $_category): ?> | |
<?php if ($i++%$_columnCount==0): ?> | |
<div class="products-grid row-fluid"> | |
<?php endif ?> | |
<div class="<?php echo $_span ?> item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"> | |
<div class="item-inner"> | |
<?php if($_category->getThumbnail()):?> | |
<a href="<?php echo $_category->getUrl() ?>" title="<?php echo $this->stripTags($_category->getName(), null, true) ?>" class="product-image"> | |
<img src="<?php | |
echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $_category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($_category->getName()) | |
?>" /></a> | |
<?php endif; ?> | |
<div class="product-item-info"> | |
<h2 class="product-name"><a href="<?php echo $_category->getUrl() ?>" title="<?php echo $this->stripTags($_category->getName(), null, true) ?>"><?php echo $_category->getName(); ?></a></h2> | |
<p><?php | |
echo Mage::helper('core/string')->truncate( | |
$this->stripTags( | |
preg_replace('/<h[0-9][^>]*>([\s\S]*?)<\/h[0-9][^>]*>/', '', $_category->getDescription()) | |
), | |
200 | |
); | |
?></p> | |
<div class="actions"> | |
<a href="<?php echo $_category->getUrl() ?>" class="button"><span><span>Detalhes</span></span></a> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?> | |
</div> | |
<?php endif ?> | |
<?php endforeach ?> | |
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment