I need to display the categories based on the website. Somebody help me How to get categories based on store or website?

3 Answers 3


you will get by this root category. the stores are related with the root category.in admin panel you can see in manage store.

    $rootid     = Mage::app()->getStore($storeid)->getRootCategoryId();
            $categories = Mage::getModel('catalog/category')
                ->addFieldToFilter('path', array('like'=> "1/$rootid/%"));
  • From your code where i can give website id? @Qaisar Satti
    – zus
    Commented Aug 2, 2019 at 11:57

Get store specific categories

The following code will fetch all active store specific categories. The following helper function does so:-

getStoreCategories($sorted=false, $asCollection=false, $toLoad=true)

$helper = Mage::helper('catalog/category');

// sorted by name, fetched as collection
$categoriesCollection = $helper->getStoreCategories('name', true, false);

// sorted by name, fetched as array
$categoriesArray = $helper->getStoreCategories('name', false, false);

Hope this helps. Thanks.


if you want the categories for specific store id:

$allCategories = Mage::getModel ( 'catalog/category' )->setStoreId(7);
$categoryTree = $allCategories->getTreeModel();
$categoryIds = $categoryTree->getCollection()->getAllIds();

if further want to get its data save in csv file:

if ($categoryIds) {
            $outputFile = "var/export/categories-and-ids.csv";
            $write = fopen($outputFile, 'w');
            foreach ( $categoryIds as $categoryId ) {
                $parentId = $allCategories->load($categoryId)->getParentId();
                $data = array($parentId, $allCategories->load($categoryId)->getName(), $categoryId);
                fputcsv($write, $data);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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