i have added a boolean custom attribute for categories using the following code

$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'popular category',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => '',
    'source'            => 'eav/entity_attribute_source_boolean',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => '',
    'required'          => false,//or true
    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do

$installer->addAttribute('catalog_category', 'attribute_popular', $attribute);

now i want to show the categories having the attribute value "yes" in home page


You can filter category collection by below code

$categories = Mage::getModel('catalog/category')
    ->addAttributeToFilter('attribute_code_here', 'value_here');

In your case:

$categories = Mage::getModel('catalog/category')
        ->addAttributeToFilter('attribute_popular', 1)
  • i want to display 6 categories only – Asha Mar 23 '16 at 11:49
  • update answer check it – Prashant Valanda Mar 23 '16 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.