1
PHTML
$this->renderCategoriesMenuHtml_ter(0,'level-top')
2
phtml对应的block文件
继承
Mage_Catalog_Block_Navigation
编写方法:
public function renderCategoriesMenuHtml_ter($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
{
$activeCategories = array();
foreach ($this->getStoreCategories_ter() as $child) {
if ($child->getIsActive()) {
$activeCategories[] = $child;
}
}
$activeCategoriesCount = count($activeCategories);
$hasActiveCategoriesCount = ($activeCategoriesCount > 0);
if (!$hasActiveCategoriesCount) {
return '';
}
$html = '';
$j = 0;
foreach ($activeCategories as $category) {
$html .= $this->_renderCategoryMenuItemHtml(
$category,
$level,
($j == $activeCategoriesCount - 1),
($j == 0),
true,
$outermostItemClass,
$childrenWrapClass,
true
);
$j++;
}
return $html;
}
public function getStoreCategories_ter()
{
$helpers = Mage::helper('catalog/category');
return $helpers->getStoreCategories_ter();
}
3
help类
继承
Mage_Catalog_Helper_Category
public function getStoreCategories_ter($sorted=false, $asCollection=false, $toLoad=true)
{
$parent = 889; //此处为:catelog ID!!!!!
$cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
if (isset($this->_storeCategories[$cacheKey])) {
return $this->_storeCategories[$cacheKey];
}
/**
* Check if parent node of the store still exists
*/
$category = Mage::getModel('catalog/category');
/* @var $category Mage_Catalog_Model_Category */
if (!$category->checkId($parent)) {
if ($asCollection) {
return new Varien_Data_Collection();
}
return array();
}
$recursionLevel = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
$storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
$this->_storeCategories[$cacheKey] = $storeCategories;
return $storeCategories;
}
如果想省劲,直接在继承的类里面直接写,反正做成版本的东西又不升级,稳定才是王道!!