【问题标题】:Show single Magento category on sidebar在侧边栏显示单个 Magento 类别
【发布时间】:2010-11-07 15:58:40
【问题描述】:

如何在侧边栏显示单个类别树?

不是产品,只有类别树。

【问题讨论】:

    标签: php model-view-controller magento categories


    【解决方案1】:

    我一直在使用Vertical Navigation 做类似的事情。

    【讨论】:

      【解决方案2】:

      为自己做这件事的正式方法是使用模块创建器创建一个模块(搜索 Magento Connect),然后:

      使用以下代码创建一个新的 phtml 文件:

      $storeCategories = $this->getCats('my-category-url-key');
              foreach ($storeCategories as $category):
                  echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
              endforeach;
      

      然后是一个名为(比如)Namespace_Yourmodule_Block_Singlecat 的块,代码如下:

       public function getCats($catName)
       { 
           $parent = Mage::getResourceModel('catalog/category_collection')
                           ->addAttributeToSelect('entity_id')
                          ->addAttributeToFilter('url_key', $catName)
                          ->getFirstItem();
           return $storeCategories = Mage::getModel('catalog/category')
              ->getCategories( $parent->getId(), $recursionLevel=1, $sorted=false, $asCollection=true, $toLoad=false);
      }
      

      那么你只需要在app\design\frontend\yourtheme\layout\yourmodule.xml布局文件中插入以下节点:

      <reference name="left">
              <block type="yourmodule/singlecat" name="singlecat" template="path/yourfilename.phtml" />
          </reference>
      

      交叉手指,向你选择的神祈祷,Magento 可能会对你的代码微笑 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多