Friday 25 December 2015

How to display Featured Product on Home Page By Category Id in Magento?

Hello Friends,


If you want to display Featured Product on Home Page according to Category Id, So Please see below code. Which Display Featured Product By Category Id.

For Display Featured Product.

First Create attribute in Magento Admin Panel.

For add attribute, 

1. You go to admin Panel

2. Mouse over on "Catalog" Menu (third menu)

3. Mouse over "Attribute" and Click on Manage Attribute (See Screenshot)





4. Open listing of all Attribute.

5. Now Click on "Add New Attribute" on right side.



6. After click "Add New Attribute" , open new page. Here, you can add your attribute. Please see below screenshot for example.



7. After Fill form, click on "Save Attribute". Now, Your "Featured" Attribute is added.

8. Now, make Products as "Featured(option 'Yes')" which, You want to assign as a Featured Product.

Now, You can paste below code, where you want to display Featured Products.

         <?php
 $categoryid = 11;   // Here you can replace from your category id
                   $category_cb = new Mage_Catalog_Model_Category();     $category_cb->load($categoryid);

$this->getProducts();

$_productCollection=$category_cb->getProductCollection()
->addAttributeToSort('entity_id', 'desc')
->addAttributeToSelect('*') ->addAttributeToFilter(array(
array('attribute' => 'featured', 'eq' => true),
));
?> 


Thanks and Enjoy 





10 comments: