0

I need to get the products from a specific category and display in a specific template style. I know you can do this on a cms page:

{{block type="catalog/product_list" name="product_list" category_id="209" column_count="4"  mode="grid" limit="25"  template="catalog/product/list.phtml"}}

But how can I do this in a php file?

1 Answer 1

0

You can do a loop through all products in a specific category and just pull back the info you need in the loop. Quick example:

<?php 

$catid=209;
$category = new Mage_Catalog_Model_Category();
$category->load($catid);

$prodCollection = $category->getProductCollection();


foreach ($prodCollection as $product):
  $product_id = $product->getId();
  $obj = Mage::getModel('catalog/product');
  $_product = $obj->load($product_id);

  //DISPLAY PRODUCT INFO HERE

  // get Product’s name
  echo $_product->getName();
  //get product’s short description
  echo $_product->getShortDescription();
  //get Product’s Long Description
  echo $_product->getDescription();
  //get Product’s Regular Price
  echo $_product->getPrice();
  //get Product’s Special price
  echo $_product->getSpecialPrice();
  //get Product’s Url
  echo $_product->getProductUrl();
  //get Product’s image Url
  echo $_product->getImageUrl();

  //ETC
endforeach;
?>

EDIT: Can you try this?

$this->getLayout()->createBlock('core/template')
->setData('category_id', '209')
->setData('column_count', '4')
->setData('mode', 'grid')
->setData('limit', '25')
->setData('name', 'product_list')
->setTemplate('catalog/product/list.phtml')->toHtml();
2
  • thanks, but is there a way to display it like the list.phtml template?
    – hello123
    Sep 14, 2017 at 8:00
  • Updated my answer Sep 14, 2017 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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