如何在magento的子类别集合中添加分页


How to add pagination in subcategory collection in magento?

我编写了以下代码来显示子类别

    <ul class="">
  <?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
?>
  <li class="">
    <div class="">
      <div class="">
        <div class=""> <a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>" class="">
          <?php
                    $imageUrl = Mage::getBaseDir('media')."/"."catalog"."/"."category"."/".$this->getCurrentCategory()->getThumbnail();
                    $imageResized = Mage::getBaseDir('media')."/"."catalog"."/"."category"."/"."resize/".$this->getCurrentCategory()->getThumbnail();

                    if (!file_exists($imageResized) && file_exists($imageUrl)) 
                    {
                    $imageObj = new Varien_Image($imageUrl);
                    $imageObj->constrainOnly(TRUE);
                    $imageObj->keepAspectRatio(TRUE);
                    $imageObj->keepFrame(FALSE);
                    $imageObj->quality(100);
                    $imageObj->resize(270, 270);
                    $imageObj->save($imageResized);
                    }
                    ?>
          <span class=""><img src="<?php echo Mage::getBaseUrl('media').'catalog/category/resize/'.$this->getCurrentCategory()->getThumbnail(); ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>"/></span> </a> </div>
      </div>
      <div class="">
        <div class="">
          <div class=""> <a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a> </div>
        </div>
      </div>
    </div>
  </li>
  <?php
endif;
endforeach;
endif;
?>
</ul>

我想在这个页面添加分页,我已经尝试了下面的解决方案,但它不工作

parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
    $pager->setAvailableLimit(array(15=>15));
    $pager->setCollection($_categories);
    $this->setChild('pager', $pager);

有没有人对如何在子类别列表页面添加分页有任何想法?

请指导我,因为我是新的magento开发。

在Mage_Catalog_Block_Navigation中我有一个自定义方法:

public function getCurrentChildCategories()
{
    if (null === $this->_currentChildCategories) {
        $layer = Mage::getSingleton('catalog/layer');
        $category   = $layer->getCurrentCategory();
        $this->_currentChildCategories = Mage::getModel('catalog/category')->getCollection();
        $pager = new Mage_Page_Block_Html_Pager();
        $pager->setLimit(100)->setCollection($this->_currentChildCategories);
        $this->setChild('pager', $pager);
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        $this->_currentChildCategories->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToSelect('image') 
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('name', 'ASC')
            ->joinUrlRewrite()
            ->load();
        $productCollection = Mage::getResourceModel('catalog/product_collection');
        $layer->prepareProductCollection($productCollection);
        $productCollection->addCountToCategories($this->_currentChildCategories);
    }
    return $this->_currentChildCategories;
}

我认为这不是最好的,但它是有效的。