<?php
$root_category = Mage::getModel('catalog/category')->load(8); // Put your root category ID here.
$subcategories = $root_category->getChildren();
$p1=1;
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
$product_id_1_12345=$category->getid();
$catid = $product_id_1_12345;
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your special offers category id!
$collection = $category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 4; // show perticulaler category product
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product):
if($p1==5) // limit show all product
{
break;
}
?>
<strong>Name : <?php echo $product->getName(); ?></strong>
<br/>
<strong>Price : <?php echo number_format( $product->getPrice(),2); ?></strong>
<br/>
<?php
$p1++;
endforeach;
}
?>
No comments:
Post a Comment