[英]Want to show sub category in magento
I want to show sub sub categories in my magento static block. 我想在我的magento静态块中显示子子类别。
For example there is Women category on that page. 例如,该页面上有“女性”类别。 I want to show all subcategories of women, and the sub categorie of this.
我想显示女性的所有子类别,以及这个的子类别。
Structure on women page will be 女性页面上的结构将为
Category 1 -> sub 1 -> Sub 1
I have already implemented some code but it dont show sub categories: 我已经实现了一些代码,但是没有显示子类别:
<?php
//If there are sub categories
$categories = $this->getCurrentChildCategories();
$categoriescount = $this->getCurrentChildCategories()->count();
if ($categoriescount > 0):
?>
<div class="sub-category-container">
<?php
//Loop through categories
foreach ($categories as $category):
?>
<div class="sub-category">
<a href="<?php echo $this->getCategoryUrl($category)?>" class="cat-image">
<?php
// If there is a thumbnail set for the category - Display it
if($imgUrl = Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()):?>
<img src="<?php echo $this->getBaseUrl()."media/catalog/category/".$imgUrl ?>" width="220" height="110" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<?php endif; ?>
</a>
<div class="inner-sub-category">
<a href="<?php echo $this->getCategoryUrl($category)?>" class="sub-link"><?php echo $category->getName()?></a>
<a href="<?php echo $this->getCategoryUrl($category)?>" class="btn"><span>View All</span></a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else:?>
<p>No Sub Categories</p>
<?php endif; ?>
Output of above code http://prntscr.com/6wcfov 以上代码的输出http://prntscr.com/6wcfov
Check out the getCategories()
method in the Categories model. 在类别模型中检查
getCategories()
方法。
$subcategories = Mage::getModel('catalog/category')->getCategories($parentCategory->getId());
foreach ($subcategories as $subcategory) {
...do things
}
You can do this recursively to get all the subcategories in a parent category. 您可以递归执行此操作以获取父类别中的所有子类别。
Display SubCategory of current category
显示当前类别的子类别
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getId()); $subCategories = explode(',', $loadCategory->getChildren()); foreach ( $subCategories as $subCategoryId ) { $cat = Mage::getModel('catalog/category')->load($subCategoryId); if($cat->getIsActive()) { echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>'; } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.