【问题标题】:How to fix repeating contents in magento?如何修复magento中的重复内容?
【发布时间】:2013-03-29 21:22:26
【问题描述】:

我的 magento 主页内容显示不止一次。我希望它们每页只出现一次。

我尝试将此代码放入 \app\code\core\Mage\Catalog\Block\Product\List.php 文件作为解决方案:

 protected function _construct()

    {
        $this->addData(array(
            'cache_lifetime'    => 900,
            'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
            'cache_key'            => $this->getCacheKey()
        ));
    } 

public function getCacheKey()
    {
        return $this->getRequest()->getRequestUri().$this->getCacheCurrencyCode();
    }

//retreive current currency code
public function getCacheCurrencyCode()
    {
        return Mage::app()->getStore()->getCurrentCurrencyCode();
    }

在此编辑之后,每当我访问我的主页时,我都会看到一些商品在畅销品类别中重复了三遍,如下面的屏幕截图所示:

出现当前错误的意外主页: http://ikelk.lt/i/131171/o_afb38c9691.JPG

理想情况下的外观(预期行为): http://ikelk.lt/i/131172/o_568243b784.JPG

感谢您的帮助。

【问题讨论】:

  • 将产品详情添加到缓存时,您还应该在缓存标签中添加产品 ID/列表类型字符串。
  • 问题与布局有关。您需要检查 CMS >Pages > home 的内容/布局以及所有 layouts.xml 文件。在某个地方你两次指定了同一个块。
  • @SatishMantri 你有没有想过这样的代码:array(Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getProduct()->getId()),如果是的话重复相同的问题内容。 @Serijo 我检查了 CMS>Pages>home,这里有不同的代码行。
  • 我的主页代码:{{block type="catalog/product_list_random" category_id="175" template="catalog/product/geriausipasiulymai.phtml" column_count="2" num_products="6"}} {{block type="catalog/product_list_random" category_id="176" template="catalog/product/naujienos.phtml" column_count="2" num_products="6"}} {{block type="catalog/product_list_random" category_id= "178" template="catalog/product/populiariausipasiulymai.phtml" column_count="2" num_products="4"}}
  • 您需要一个类别 ID 标签作为缓存标签。

标签: html magento caching block


【解决方案1】:

你好,我想你检查一下模板路径提示,这样你就会得到重复的模板调用。

Goto->Admin->System->Configuration->Current Configuration Scope(选择你的商店)->Advanced(left)->Developer->Debug->Template path hints 选择yes->刷新主页

【讨论】:

    猜你喜欢
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2015-09-29
    • 2018-01-04
    相关资源
    最近更新 更多