Display featured product homepage

Display featured product homepage

<?php
$featuredProducts = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status',1)
    ->addAttributeToFilter('visibility',4)
    ->addAttributeToFilter('new_products', 1);
?>
<section class="greyBg">
    <div class="main-container col1-layout">
        <h2 class="align-center page-title">Feature Items</h2>
        <ul class="products-grid products-grid--max-4-col ">
            <?php foreach($featuredProducts as $featuredProduct) : ?>
                <li class="item">
                    <a href="<?php echo $featuredProduct->getProductUrl();?>" class="displayBlock">
                        <img src="<?php echo Mage::helper('catalog/image')->init($featuredProduct, 'thumbnail')->resize(280,280)?>" alt="<?php echo $featuredProduct->getName(); ?>"/>
                    </a>
                    <p><?php echo $featuredProduct->getName(); ?>
                    <span class="displayBlock fontBold"><?php echo Mage::helper('core')->currency($featuredProduct->getPrice(),true,false); ?></span></p>
                    <?php if($featuredProduct->isSaleable() && ($featuredProduct->getTypeId() == 'simple')): ?>
                        <button type="button" title="" class="button btn-cart" onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($featuredProduct); ?>')">
                            <span><span><?php echo 'Add to Cart'; ?></span></span>
                        </button>
                    <?php elseif ($featuredProduct->isSaleable() && ($featuredProduct->getTypeId() == 'configurable')): ?>
                        <button type="button" title="" class="button btn-cart" onclick="setLocation('<?php echo $featuredProduct->getProductUrl(); ?>')">
                            <span><span><?php echo 'View Details'; ?></span></span>
                        </button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
</section>

Share this Tutorial