2017-06-06 35 views
0

我有一個文件,正在循環通過我的類別和子類別。我能夠成功地呼應所有我不明白的類別及其鏈接循環遍歷Magento類別,Meta關鍵字和描述

爲什麼這些(keywords和description)不附和

<?php echo htmlspecialchars($this->getKeywords()) ?> 
<?php echo htmlspecialchars($this->getDescription()) ?> 

該文件位於這裏 應用程序/設計/前端/ mystoretheme /默認/模板/目錄/類別/ listofcats.phtml

然後即時將它放在一個cms頁面塊{{塊類型=「目錄/導航」名稱=「catalog.category」模板=「目錄/類別/ listofca ts.phtml「}}

我們的目標是能夠在同一<李中顯示的每個關鍵字及其說明的類別列表>和循環給我這樣

  • 類別
  • 列表
  • 關鍵詞
  • 說明

這裏是我的代碼。由於他們不工作,我省略了關鍵字和描述的嘗試。

<div class="block block-list block-categories"> 
<div id="block-categories" class="block-title active"> 
    <strong><span>Categories </span></strong> 
</div> 
<div id="leftnav" class="block-content" style="display:block"> 
    <?php $helper = $this->helper('catalog/category') ?> 
     <?php $categories = $this->getStoreCategories() ?> 
    <?php if (count($categories) > 0): ?> 
     <ul id="leftnav-tree" class="level0"> 
      <?php foreach($categories as $category): ?> 
       <li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>"> 
        <a href="<?php echo $helper->getCategoryUrl($category) ?>"><span><?php echo $this->escapeHtml($category->getName()) ?></span></a> 
        <?php //if ($this->isCategoryActive($category)): ?> 
         <?php $subcategories = $category->getChildren() ?> 
         <?php if (count($subcategories) > 0): ?> 
          <ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1"> 
           <?php foreach($subcategories as $subcategory): ?> 
            <li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>"> 
             <a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a> 
             <?php $secondLevelSubcategories = $subcategory->getChildren() ?> 
             <?php if (count($secondLevelSubcategories) > 0): ?> 
          <ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2"> 
           <?php foreach($secondLevelSubcategories as $secondLevelSubcategory): ?> 
            <li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory)): ?> active<?php endif; ?>"> 
             <a href="<?php echo $helper->getCategoryUrl($secondLevelSubcategory) ?>"><?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?></a> 
            </li> 
            <?php endforeach; ?> 
          </ul> 
          <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script> 
         <?php endif; ?> 
           <?php endforeach; ?> 
          </ul> 
          <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script> 
         <?php endif; ?> 
        <?php //endif; ?> 
       </li> 
      <?php endforeach; ?> 
     </ul> 
     <script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script> 
    <?php endif; ?> 
</div> 

+0

什麼版本的Magento您使用的是? – spiil

回答

1

請檢查:

<?php 
$categories = Mage::getModel('catalog/category') 
       ->getCollection() 
       ->setStoreId(Put the store id here) 
       ->addAttributeToSelect('*') 
       ->addIsActiveFilter(); 
foreach ($categories as $category) { 
    echo $category->getName(); 
    echo "-"; 
    echo $category->getMetaKeywords(); 
    echo "-"; 
    echo $category->getMetaDescription(); 
    echo "<br/>"; 
} 
?> 
+0

但是,這很好,我只需要顯示我在不是所有商店類別上顯示網頁的商店。我將如何修改它? – monjexpress

+0

只需執行以下操作: - > setStoreId($ storeId)請輸入您想要的商店的商店標識。 –

+0

請參閱我上面修改的答案。如果你喜歡它並且工作正常,那麼請接受答案+向上投票。謝謝。 –