可以創建自定義塊如下,並設置分頁像here
<?php echo $this->getLayout()->createBlock('yourmodule/product_customlist')->setTemplate('catalog/product/list.phtml')->toHtml() ?>
UPDATE
應用的/ etc /模塊/ Custom_Products.xml
如下
<config>
<modules>
<Custom_Products>
<active>true</active>
<codePool>local</codePool>
</Custom_Products>
</modules>
</config>
應用程序/代碼/本地/自定義/產品的/ etc/config.xml中
文件如下
<config>
<global>
<blocks>
<customproducts>
<class>Custom_Products_Block</class>
</customproducts>
</blocks>
</global>
</config>
應用程序/代碼/本地/ Custom/Products/Block/Customlist.php
文件如下
<?php
class Custom_Products_Block_Customlist extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
// We get our collection through our model
$this->_collection = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*') // add all attributes - optional
->addAttributeToFilter('status', 1) // enabled
->addAttributeToFilter('visibility', 4) //visibility in catalog,search
->setOrder('price', 'ASC'); //sets the order by price
// Instantiate a new Pager block
$pager = new Mage_Page_Block_Html_Pager();
// We set our limit (here an integer store in configuration).
// /!\ The limit must be set before the collection
$pager
->setLimit(5)
->setCollection($this->_collection);
// Add our Pager block to our current list block
$this->setChild('pager', $pager);
}
}
?>
應用程序/設計/ YOUR_PACKAGE/YOUR_THEME /模板/目錄/產品/ customlist。PHTML
如下
<?php
$_productCollection=$this->_collection;
...
your products code here
...
?>
<?php
echo $this->getChildHtml('pager');
?>
檢查,如果它是爲你工作。
你好Dushyant,這種方法會有道理,但因爲我不完全是一個magento專家,你可以幫助我通過這個或給我看一些簡單的步驟如何做到這一點? – vikingen
檢查我更新的答案 –