Source: https://stackoverflow.com/a/12288000/158325
Found a working solution using Alan Storm's advice.
/template/custom/featured-product.phtml
<?php
$_categoryId = $this->getCategoryId();
$_productCollection = Mage::getModel('catalog/category')->load($_categoryId)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', 4)
->setOrder('price', 'ASC');
?>
<div class="featured-product">
<h2><?php echo $this->__( $this->getLabel() ); ?></h2>
<?php foreach ($_productCollection as $_product): ?>
<div class="item">
<a class="product-image" href="<?php echo $_product->getProductUrl() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</a>
<a class="product-name" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<?php
// Note: Exit after first product.
break;
?>
<?php endforeach ?>
</div>
In short, the collection is manually generated rather than receiving a collection (as my initial attempt did):
<?php $_productCollection = $this->getLoadedProductCollection() ?>
<?php $_collectionSize = $_productCollection->getSize(); ?>
Using in a CMS Page:
{{block type="core/template" category_id="13" label="Product of the Month" template="custom/featured-product.phtml" }}
Using in a template:
/layout/local.xml
<default>
<reference name="footer">
<block type="core/template" name="custom.featuredProduct" as="featured_product" template="custom/featured-product.phtml">
<action method="setData"><key>category_id</key><value>13</value></action>
<action method="setData"><key>label</key><value>Product of the Month</value></action>
</block>
</reference>
</default>
/template/page/html/footer.phtml
<?php echo $this->getChildHtml('featured_product') ?>
Helpful resources:
How to get a product collection:
Using magic getters/setters:
The simplest and easiest to implement is to use the Custom Design
tab for the category you want to force the grid / list view by entering the following in the Custom Layout Update
:
Grid View:
<reference name="product_list_toolbar">
<action method="setData"><key>_current_grid_mode</key><value>grid</value</action>
</reference>
List View:
<reference name="product_list_toolbar">
<action method="setData"><key>_current_grid_mode</key><value>list</value></action>
</reference>
Best Answer
You can add category filter in manage products page to sort your product, you can do it manually just add one column category on product grid.
Here is a nice answer of adding category column in product grid https://stackoverflow.com/questions/3472702/add-categories-column-to-the-product-grid-in-magento-admin
Just put below code in your Grid.php file
Or else you can use free extension which are available to add extra grid in your manage product grid.
This will add extra category column in grid and you are able to sort your product according to category.
http://www.magentocommerce.com/magento-connect/enhanced-admin-product-grid.html http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html