简体   繁体   中英

Magento - product list into CMS page

I want to show a category product in a CMS page. For that process I have to insert the product list of a particular category inside a CMS page, to do it from backend I add a static block like this

{{block type="catalog/product_list" 
        name="home.catalog.product.list" 
        alias="products_homepage" category_id="4" 
        template="catalog/product/list.phtml"}}

How can I do the same thing inside phtml ?

To do the same from phtml file, use:

   <?php echo $this->getLayout()->createBlock("catalog/product_list")
->setCategoryId(4)->setTemplate("catalog/product/list.phtml")->toHtml();?>

This can be easily achieved through xml

<reference name="content">
    <block type="catalog/product_list" name="home" template="catalog/product/list.phtml">

            <!-- Product List View -->
            <action method="setCategoryId"><category_id>40</category_id></action>
            <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
            </block>
            <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>

    </block>

Just replace category id with your category id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM