修改首页导航菜单的位置
将首页的导航菜单移入到 banner下面的方法:
进入后台,在cms-page-设计:
右边:
1.<reference name="content">
2.<block type="catalog/product_new" name="home.catalog.product.new" template="catalog/product/tabMenu.phtml" after="cms_page">
3.<action method="setProductsCount"><count>4</count></action>
4.<action method="addPriceBlockType">
5.<type>bundle</type>
6.<block>bundle/catalog_product_price</block>
7.<template>bundle/catalog/product/price.phtml</template>
8.</action>
9.<action method="setColumnCount"><count>4</count></action>
10.</block>
11.</reference>
在第2行之前插入:
<block type="catalog/navigation" name="cms_catalog" template="catalog/catalog.phtml"/>
然后在 app\design\frontend\rwd\default\template\catalog 下新建 catalog.phtml 文件,其内容为以下代码:
<?php $current_cat = $this->getCurrentCategory();?>
<?php $current_cat = (is_object($current_cat) ? $current_cat->getName() : '');?><div class="catalog">
<?php $collection = $this->getStoreCategories();?>
<?php foreach ($collection as $_category):?>
<?php if ($_category->getName() == $current_cat) {?>
<a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?><br/>
<?php }else{ ?>
<h2><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></h2>
<?php }?>
<?php foreach($_category->getChildren() as $_childCategory):?>
<?php if ($_childCategory->getName() == $current_cat) {?>
<a href="<?php echo $this->getCategoryUrl($_childCategory)?>"><?php echo $_childCategory->getName()?></a><br/>
<?php }else{ ?>
<h6><a href="<?php echo $this->getCategoryUrl($_childCategory)?>"><?php echo $_childCategory->getName()?></a></h6>
<?php }?>
<?php foreach($_childCategory->getChildren() as $_cchildCategory):?>
<?php if ($_cchildCategory->getName() == $current_cat) {?>
<a href="<?php echo $this->getCategoryUrl($_cchildCategory)?>"><?php echo $_cchildCategory->getName()?></a><br/>
<?php }else{ ?>
<h6 style="margin-left:10px;"><a href="<?php echo $this->getCategoryUrl($_cchildCategory)?>"><?php echo $_cchildCategory->getName()?></a></h6>
<?php }?>
<?php endforeach?>
<?php endforeach?>
<?php endforeach?>
</div>
这样前台就可以看到效果了。。
可以看到整个菜单。如果只想看一级菜单的话:
<?php $current_cat = $this->getCurrentCategory();?>
<?php $current_cat = (is_object($current_cat) ? $current_cat->getName() : '');?>
<div class="catalog">
<?php $collection = $this->getStoreCategories();?>
<ul id="tabs" class="tabs">
<?php $i=0; foreach ($collection as $_category):?>
<li onclick="tab(<?php echo $i;?>)"> <?php echo $_category->getName()?></li>
<?php
$i++;
?>
<?php endforeach?>
</ul>
</div>
然后可以做一个切换的tab。
在app.js最后添加:
function tab(x){
var lis=document.getElementById("tabs").getElementsByTagName("li");
for(var i=0;i<lis.length;i++){
lis[i].className="";
lis[x].className="liActive";
document.getElementById('tabs-con'+i).style.display="none";
document.getElementById('tabs-con'+x).style.display="block";
}
};