来源:http://studyjphp.blog.163.com/blog/static/131261219201171293215624/
在cms->>page里的design 的 layout update XML 里可以写 magento 的xml 语句
添加
------------------------------------------------------
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/leftnav.phtml" before="-" />
</reference>
========================================================
写好样式 即可。
默认的分类导航在catalog.xml里定义
------------------------------------------------------------------
<reference name="top.menu">
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>
=======================================================
在首页page.xml里的定义
----------------------------------------------------
<block type="page/html_header" name="header" as="header">
................................................
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
</block>
.....................................................................
</block>
================================================
在相应的首页模板(如:2columns-left.phtml)里显示
---------------------------------------------------
<?php echo $this->getChildHtml('header') ?>
====================================================
流程:
1 在首页(page.xml)里的区块(name="header")开辟了一个区块,name="top.menu"
2 在分类总页(catalog.xml)里引用区块 name="top.menu"( <reference name="top.menu">),在区块name="top.menu"下开辟一个新的区块name="catalog.topnav",并引用模板template="catalog/navigation/top.phtml"/
3 在首页 getChildHtml('header') 显示出来。
参考:
http://vsfor.com/archives/85
只获得二级分类目录
------------------------------------------------------------------
<ul id="leftnav">
<?php
$_categories = $this->getStoreCategories();
foreach($_categories as $cat) {
$categoryid = $cat->getId();
$_category = Mage::getModel('catalog/category')->load($categoryid); //$categoryid for which the child categories to be found
$child_categories = $_category->getChildren();
$all_child_categories = $_category->getAllChildren(); //array consisting of all child categories id
$child = strtok($child_categories,",");
while($child !== false){
$childcat = Mage::getModel('catalog/category')->load($child);
echo '<li class="current"><a href=" ' . $childcat->getUrlPath() . '">' . $childcat->getName() .'</li>';
$child = strtok(",");
}
}
?>
</ul>