I have a homepage.phtml which will create a block by calling a new.phtml


<div class="home-page-new-product">
    <p class="new-product-title"><?php echo $this->__('New Product') ?></p>
    <?php echo $this->getLayout()->createBlock("catalog/product_new")->setTemplate("catalog/product/new.phtml")->toHtml() ?>

first line of new.phtml

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

The question is how can I display products of specific category, is it possible to simply adjust the code of new.phtml only?


The block type catalog/product_new does not allow you to specify a category id. You could try using the catalog/product_list block instead which does allow setting a category id.

echo $this->getLayout()->createBlock("catalog/product_list")->setTemplate("catalog/product/list.phtml")->setCategoryId('category_id')->toHtml();

I guess you are looking for something like this: In CMS Pages > Home Page, add this code:

{{block type="catalog/product_new" column_count="4" category_id="5" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.