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?

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();
  • thanks, but is there a way to display it like the list.phtml template? – hello123 Sep 14 '17 at 8:00
  • Updated my answer – KiwisTasteGood Sep 14 '17 at 15:30

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.