2013-08-05 153 views
0

我对自定义页面上显示的Magento cms静态块有一些疑问。 例如,我有3个静态块(块1,块2,块3),我需要显示块1在类别1和子类别1,块2在类别2和子类别2,块3在其他页面(家庭,约等)在自定义页面上显示自定义静态块Magento

我尝试使用Mage::app()->getFrontController()->getRequest()->getRequestUri()

但我接收到的请求,如“category1.html”如果我们打算到这一类的子类 - 块改变为默认。

如果使用Mage::app()->getFrontController()->getRequest()我收到“目录/类别/视图/ ID/ID_NUMBER”

我真的不知道如何来解决这个问题。

感谢您的回答!在你

+0

你的问题是有点混乱。你是否试图将静态块分配给特定的类别? – Axel

+0

是的,我只有3个类别+子类别和其他页面,如主页,运输等,我想显示在这个类别(cat1 + subcat1 = block1等)的管理员创建3个不同的静态块和其他页面的块4。 – Oleg

+0

为什么不能使用允许您将静态块分配给类别的内置功能?我添加了一个答案,概述了执行此操作的步骤。 – Axel

回答

1

您可以使用自定义布局更新功能将一个块添加到页面的特定部分。

注意:如果您有自定义主题,则页脚的引用名称可能会有所不同。这种方法已经过测试工作在现代主题包含Magento的

  1. 转到目录>管理类别
  2. 选择你想你的块分配给该类别。
  3. 转至自定义设计选项卡。
  4. 设置使用父类别设置No
  5. 自定义布局更新,插入你的静态块以下XML
    <reference name="bottom.container">
    <block type="cms/block" name="my_footer_block"> <action method="setBlockId"> <block_id>my_footer_block</block_id>
    </action>
    </block>
    </reference>

  6. 标识符(BLOCK_ID)更换my_footer_block

  7. 根据清除Magento缓存系统>缓存管理并刷新分类页面。

如果这不起作用,那么参考名称可能对您正在使用的主题不正确。您可以通过查看app/design/frontend/[THEME PARENT]/[THEME CHILD]/layout/page.xml并在文件中搜索page/html_footer来查看参考名称。

在该文件中,你会发现这样的事情:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"> 
    <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label"> 
     <label>Page Footer</label> 
     <action method="setElementClass"><value>bottom-container</value></action> 
    </block> 
    <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/> 
     <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/> 
    </block> 
    <block type="core/text_list" name="before_body_end" as="before_body_end" translate="label"> 
     <label>Page Bottom</label> 
    </block> 
</block> 

注意name属性为page/html_wrapper块。这是在步骤步骤5中提供的代码中使用的名称参考。如果与bottom.container不同,请更改bottom.container以匹配page.xml文件中的内容。

+0

谢谢你的帮助!这个例子真的帮助我! – Oleg

0

覆盖的catalog.xml本地模块 添加在 内容参考

在您目录/分类/ voew.phtml 添加以下代码

$ _current_category = $这 - > getCurrentCategory();

if(cond =='1st category'){ echo $ this-> getChildHtml('block1'); }

类似地,对于其它的块

0

可以简单地分配使用内置的功能的Magento提供了一个静态块特定类别。

  1. 转到目录>管理类别
  2. 单击要块分配给左侧的类别。
  3. 转到显示设置标签
  4. 设置显示模式要么Static block onlyStatic block with products
  5. 设置CMS块到您要在此类别上显示的静态块。
  6. 点击保存类别按钮。

对不同的类别重复此步骤。您可以选择一个唯一的静态块,或者按照这种方式将相同的一个分配给多个类别。

+0

我试过这个版本,但我需要在页脚中显示当前块 – Oleg

+0

我已经添加了另一个答案,详细说明如何做到这一点。今后,请详细说明您尝试实现的所有细节,直至放置在页面上(在您的情况下,类别页脚中的静态块)。这将允许这里的人给你一个正确的答案,你正在努力达到的目标。 – Axel

1

这可能帮助你

Strategy : Check current page is whether current category is available on current page or not, If available then you can check it's level and depending on that you can show you block 

Solution : 
$_current_category=$this->getCurrentCategory(); 
1)get current category and if category not available then show default block 
2)if category found get it's level $_current_category->getLevel() and then you can place your block accordingly