【问题标题】:Showing custom static block on the custom page Magento在自定义页面 Magento 上显示自定义静态块
【发布时间】:2013-08-05 14:33:41
【问题描述】:

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

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

但我收到了类似“category1.html”的请求,如果我们要进入该类别的子类别 - 块将更改为默认值。

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

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

感谢您的回答!

【问题讨论】:

  • 你的问题有点混乱。您是否尝试将静态块分配给特定类别?
  • 是的,我只有 3 个类别 + 子类别和其他页面,例如主页、运输等,我想显示 3 个在管理员中创建的关于此类别的不同静态块(cat1+subcat1 = block1 等)和其他页面的块 4..
  • 为什么不能使用允许您将静态块分配给类别的内置功能?我添加了一个答案,概述了执行此操作的步骤。
  • 感谢您的回答,但此块需要显示在页脚中

标签: magento content-management-system block frontend routes


【解决方案1】:

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

注意:如果您有自定义主题,页脚的参考名称可能不同。此方法已经过测试,可用于 Magento 随附的 Modern 主题

  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 文件中的内容。

【讨论】:

    【解决方案2】:

    这可能对你有帮助

    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
    

    【讨论】:

      【解决方案3】:

      在本地模块中覆盖 catalog.xml 加入 在内容参考中

      在你的目录/category/voew.phtml 添加此代码

      $_current_category=$this->getCurrentCategory();

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

      其他区块也是如此

      【讨论】:

        【解决方案4】:

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

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

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

        【讨论】:

        • 我试过这个版本,但我需要在页脚中显示当前块
        • 我添加了另一个答案,详细说明了如何执行此操作。将来,请详细说明您要实现的目标,直至页面上的位置(在您的情况下,是类别页脚中的静态块)。这将使这里的人们能够为您尝试实现的目标提供正确的答案。
        猜你喜欢
        • 1970-01-01
        • 2018-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多