2012-06-16 48 views
1

我创建了一个名为nav_container的div,我希望将Magento产品类别放置在该div中,而不是默认标题中。如何在我自己的div中添加产品类别?

要做到这一点,最简单的方法是什么?我已经研究了很长时间没有解决方案。感谢您的任何建议。我正在使用Magento 1.7。

+1

你可能想给你的问题一个更相关的标题。现在它只告诉我们这是关于Magento相关的东西,这已经是一个标签。 – Bart

回答

3

有几种方法来实现这一目标:

  1. 复制app/design/frontend/base/default/page/html/topmenu.phtmlapp/design/frontend/your_package/your_theme和简单地添加在你的包裹格。

  2. 编辑app/design/frontend/your_package/your_theme/page/html/header并找到行:<?php echo $this->getChildHtml('topMenu') ?>,只是围绕着它与你的div

  3. 你也可以使用布局文件,特别是page/html_wrapper块 - 但是对于这个简单的例子中选择1或2个最有可能是最好的选择

编辑

请参阅下面的正确的解决方案后意识到你的混淆块

好吧,首先,块在Magento中有一个非常具体的含义,完全不同于一个HTML标记。你可以找到块的定义在这里:http://www.magentocommerce.com/design_guide/articles/magento-design-terminologies4#term-blocks

现在,移动顶部导航在1.7 CE:

与以往一样,在Magento的布局,你有两个主要选择:在基地布局文件复制到当前主题和编辑,或者在主题中使用local.xml文件来覆盖所有基础布局。

每个人都有优点和缺点 - 尽管我会主张你使用local.xml,除非有特定的理由不这样做。但它是完全由你选择哪种方法

app/design/frontend/your_package/your_theme/layout/local.xml 
<layout version="0.1.0"> 

    <!-- Other layout xml --> 

    <!-- 
     Unset the nav from the header 
    --> 
    <reference name="header"> 
     <action method="unsetChild"><alias>topMenu</alias></action> 
    </reference> 

    <!-- 
     Insert it into your new containing block 
    --> 
    <reference name="nav_container"> 
     <action method="insert"><alias>top.menu</alias></action> 
    </reference> 

    <!-- Other layout xml --> 

</layout> 

2.复制在基本文件:)

1.使用local.xml中

第一,复制app/design/frontend/base/default/layout/page.xmlapp/design/frontend/your_package/your_theme/layout/page.xml

找到头块,而如果不变将是完全如下:

<block type="page/html_header" name="header" as="header"> 
    <block type="page/template_links" name="top.links" as="topLinks"/> 
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/> 
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label"> 
     <label>Navigation Bar</label> 
     <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/> 
    </block> 
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label"> 
     <label>Page Header</label> 
     <action method="setElementClass"><value>top-container</value></action> 
    </block> 
</block> 

,并更改为:

<block type="page/html_header" name="header" as="header"> 
    <block type="page/template_links" name="top.links" as="topLinks"/> 
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/> 
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label"> 
     <label>Page Header</label> 
     <action method="setElementClass"><value>top-container</value></action> 
    </block> 
</block> 

在这一点上,你只需从布局删除top.menu块。

接下来,您需要将块添加回正确节点下的布局:nav_container。

所以,无论你正在声明你nav_container块添加一个子节点的XML你删除即:

<block type="core/text_list" name="top.menu" as="topMenu" translate="label"> 
    <label>Navigation Bar</label> 
    <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/> 
</block> 

最后清空缓存并重新加载页面。

+0

前两个不起作用:它会简单地将导航菜单包装在具有相同ID的div中,但仍然嵌套在标题div内。您能否详细说明选项3? – user1448260

+0

因此,您想要将导航栏完全移出页眉,并将其完全放入另一个单独的块中? –

+0

是的,我做了一个自定义模板,你把它称为'块',我只是将其称为div。所以我想用div命名为'left_container'。 –

相关问题