可以创建自定义块如下,并设置分页像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
检查我更新的答案 –