How to create Featured product in Magento home page?
Create new Featured attribute
Create a new attribute by going to Catalog > Attributes > Manage Attributes > Add New Attribute.
Attribute Properties
Attribute Identifier: featured
Scope: Store View
Catalog Input Type for Store Owner: Yes/No
Unique Value (not shared with other products): No
Values Required: No
Input Validation for Store Owner: None
Apply To: All Product Types
Front End Properties
Use in quick search: No
Use in advanced search: Yes
Comparable on Front-end: No
Use In Layered Navigation (Can be used only with catalog input type ‘Dropdown’): No
Visible on Catalog Pages on Front-end: Yes
Manage Label/Options
Default: Featured Product
English: Featured Product
Please create a file name “featured.phtml” location <your_theme>/catalog/product/featured.phtml.
<div id=”home-featured”>
<div class=”page-title featured-title”>
<h3><?php echo $this->__(‘Featured products’) ?></h3>
</div>
<?php
// some helpers
$_helper = $this->helper(‘catalog/output’);
$storeId = Mage::app()->getStore()->getId();
$catalog = $this->getLayout()->createBlock(‘catalog/product_list’)->setStoreId($storeId);
// get all products that are marked as featured
$collection = Mage::getModel(‘catalog/product’)->getCollection();
$collection->addAttributeToSelect(‘featured_product’);
$collection->addFieldToFilter(‘featured’, 1);
// if no products are currently featured, display some text
if (!$collection->count()) :
?>
<p class=”note-msg”><?php echo $this->__(‘There are no featured products at the moment.’) ?></p>
<?php else : ?>
<div class=”category-products”>
<?php
$_collectionSize = $collection->count();
$_columnCount = 4;
$i = 0;
foreach ($collection as $_product) :
$_product = Mage::getModel(‘catalog/product’)->setStoreId($storeId)->load($_product->getId());
?>
<?php if ($i++%$_columnCount==0): ?>
<ul class=”products-grid”>
<?php endif ?>
<li class=”item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>”>
<a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>” class=”product-image”><img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(135); ?>” width=”135″ height=”135″ alt=”<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>” /></a>
<h2 class=”product-name”><a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->stripTags($_product->getName(), null, true) ?>”><?php echo $_helper->productAttribute($_product, $_product->getName(), ‘name’) ?></a></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, ‘short’) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class=”actions”>
<?php if($_product->isSaleable()): ?>
<button type=”button” title=”<?php echo $this->__(‘Add to Cart’) ?>” class=”button btn-cart” onclick=”setLocation(‘<?php echo $catalog->getAddToCartUrl($_product) ?>’)”><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button>
<?php else: ?>
<p class=”availability out-of-stock”><span><?php echo $this->__(‘Out of stock’) ?></span></p>
<?php endif; ?>
<ul class=”add-to-links”>
<?php if ($this->helper(‘wishlist’)->isAllow()) : ?>
<li><a href=”<?php echo $this->helper(‘wishlist’)->getAddUrl($_product) ?>” class=”link-wishlist”><?php echo $this->__(‘Add to Wishlist’) ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$catalog->getAddToCompareUrl($_product)): ?>
<li><span class=”separator”>|</span> <a href=”<?php echo $_compareUrl ?>” class=”link-compare”><?php echo $this->__(‘Add to Compare’) ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type=”text/javascript”>decorateGeneric($$(‘ul.products-grid’), [‘odd’,’even’,’first’,’last’])</script>
</div>
<?php endif ?>
</div>
Please add below code in CMS -> Home page
{{block type=”core/template” name=”home.featured” template=”catalog/product/featured.phtml”}}
hope it will work.