I have the following code that will display list of subcategories in a category page and I want to exclude several subcategories from displaying but is active in the Navigation Menu.
Category Tree Scenario:

--- Men
--- Women
--- Kids

--- Men
--- Women
--- Kids

When I clicked on the Apparel category which is part of the Menu/Navigation at top. It will go to the category page of the apparel and display only the subcategory name and subcategory image of Men, Women and Kids. But I to exclude Kids. But it will still be visible in the navigation when you hover Apparel all three subcategories are part of the drop down.

<ul class="products-grid widget-grid">
     <!--  -->
      $currentCat = Mage::registry('current_category');
      if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() ){
         // current category is a toplevel category
         $loadCategory = $currentCat;
         // current category is a sub-(or subsub-, etc...)category of a toplevel category
         // load the parent category of the current category
         $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
          $subCategories = explode(',', $loadCategory->getChildren());

          foreach ( $subCategories as $subCategoryId )
             $cat = Mage::getModel('catalog/category')->load($subCategoryId);
                echo '<li class="grid_3 item alpha">
                <div class="product-border">
                <div class="product-img-box">
                <a href="'.$cat->getURL().'" class="product-image" >
                <div class="hover-box">
                   <img src="'.$cat->getImageUrl().'" />
                   <span class="image-box"></span>
                <a class="fancybox" rel="category-gallery" title="'.$cat->getName().'" href="'.$cat->getURL().'">&nbsp;</a>
                <h2 class="product-name">
                <a href="'.$cat->getURL().'">'.$cat->getName().'</a>
                <div class="title-divider"><span>&nbsp;</span></div>
                <div class="clear"></div>
     <!--  -->

Looking forward for your help guys. Thank you!


I think best way is you can crate one category attribute which can be use to manage it on category list page.

For example create one category attribute called "Show on list" with "Yes,No" options and based on this options you can skip those categories from list and it will still available on top navigation.


Create one file on root called createAttribute.php and add below code in that file and run url in browser like http://example.com/createAttribute.php

This will create new category attribute and you can see it in admin. Same thing you can do using module setup also.


$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute('catalog_category', 'show_in_list',  array(
    'group'    => 'General Information',
    'type'     => 'int',
    'label'    => 'Show in list',
    'input'    => 'select',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => false,
    'default'           => 0,
    'source' => 'eav/entity_attribute_source_boolean'

Not in your phtml code as you show above just add one more condition like

if($cat->getIsActive() && $cat->getShowInList()){...

This will only list those categories which you set option YES in admin.

  • but how do I achieve that with my code? – KiD Cajes Dec 14 '15 at 10:01
  • Edited my answer – Akhilesh Patel Dec 14 '15 at 12:16
  • It worked. But can you help me, how to load the current category and it's children instead? – KiD Cajes Dec 16 '15 at 7:15

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.