在自定义页面Magento上显示自定义静态块



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

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

但我收到了类似"category1.html"的请求,如果我们转到这个类别的子类别,块将更改为默认值。

如果使用Mage::app()->getFrontController()->getRequest(),我收到"catalog/categy/view/id/id_number"

我真的不明白如何解决这个问题。

谢谢你的回答!

您可以使用自定义布局更新功能为特定类别向页面的特定部分添加块。

注意:如果您有自定义主题,页脚的引用名称可能不同。这种方法已经过测试,适用于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. my_footer_block替换为静态块的标识符(block_id)。

  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>

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

这可能有助于

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

覆盖本地模块中的catalog.xml加载项内容参考

在您的catalog/category/voew.html中添加此代码

$_current_category=$this->getCurrentCategory();

if(cond=="第一类"){echo$this->getChildHtml('block1');}

类似地,对于其他块

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

  1. 转到目录>管理类别
  2. 单击左侧要将块指定给的类别
  3. 转到显示设置选项卡
  4. 显示模式设置为Static block onlyStatic block with products
  5. CMS块设置为要在此类别中显示的静态块
  6. 单击保存类别按钮

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

最新更新