2015-11-25 60 views
0

Hy!我試圖在cms頁面上顯示類別。我嘗試了網絡上的所有解決方案,但沒有一個適用於我。我試過的最後一個是這個。Magento靜態模塊現在顯示在CMS頁面

1.I've在我的CMS頁面的內容標籤添加以下代碼: {{塊類型= 「目錄/導航」 模板= 「目錄/類別/ list.phtml」}}

2。我已經創建了list.phtml,並將該文件放在app/design/theme-name/template/catalog/category中。

這裏是代碼我pf的文件

<?php foreach ($this->getStoreCategories() as $_category): ?> 
    <?php $open = $this->isCategoryActive($_category); ?> 
    <?php 
    $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); 
    $layer = Mage::getSingleton('catalog/layer'); 
    $layer->setCurrentCategory($cur_category); 
    if ($immagine = $this->getCurrentCategory()->getImageUrl()): 
     ?> 
     <div class="catalog-image"> 

      <div> 
       <a href="<?php echo $this->getCategoryUrl($_category)?>"> 
        <img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="313" height="151" /> 
       </a> 
      </div> 

      <div class="left"><h2><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></h2></div> 

     </div> 
    <?php endif; ?> 
<?php endforeach; ?> 

我做錯了什麼?謝謝 !

+0

您尚未在靜態塊中提供類別標識。 –

回答

0
  1. 添加該代碼在您的CMS頁面的內容標籤:

{{塊類型= 「核心/模板」 模板= 「頁/類別-list.phtml」} }

  • 在主題創建一個文件,例如 「類別-list.phtml」
  • 路徑:應用程序/設計/ 主題名稱 /template/page/categories-list.phtml

    在這個文件中,寫了下面的代碼,以獲得所有類別的集合:

    <?php 
    $categories = Mage::getModel('catalog/category') 
          ->getCollection() 
          ->addAttributeToSelect('*') 
          ->addIsActiveFilter(); 
    ?> 
    

    如果只希望父母的某些類別,使用下面的代碼:

    <?php 
        $parent_category_id = 5; // this is ID of parent category 
        $categories = Mage::getModel('catalog/category')->getCategories($parent_category_id); 
    ?> 
    

    要在屏幕上顯示的類別,使用循環,看下面:

    <?php foreach ($categories as $category): ?> 
    
        <p><?php echo $category->getImageUrl(); ?></p> 
        <p><?php echo $category->getName(); ?></p> 
    
    <?php endforeach; ?> 
    

    如果使用父類的類別來顯示圖像,使用下面的代碼:

    Mage::getModel('catalog/category')->load($category->getId())->getImageUrl();

    +0

    我確實喜歡你說的但沒有工作。我的magento版本是1.9.2.2 –

    0
    1. 在名稱導航目錄下創建一個文件夾,並將您的list.phtml文件放在那裏它將工作。

      {{塊類型= 「核/模板」 模板= 「目錄/導航/ list.phtml」 CATEGORY_ID = 「507」}}

    2. 類別顯示模式shuould是在顯示設定靜塊。

    +0

    我確實像你說過的,但沒有工作。我的magento版本是1.9.2.2 –

    相關問題