Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:28:00+00:00 2026-05-24T11:28:00+00:00

So I want this code to display the categories children and their children on

  • 0

So I want this code to display the categories children and their children on my view.phtml page in app/frontend/default/default/catalog/category/

So when you see the category page you see ALL of the children from all the sub categories

Here is what I got, it is showing sub categories, but not their children.

    <?php
    $_category  = $this->getCurrentCategory(); 
    $collection = Mage::getModel('catalog/category')->getCategories($_category-       >entity_id);
    $helper     = Mage::helper('catalog/category');
    ?>

   <ul>
    <?foreach ($collection as $cat):?>
            <?php if($_category->getIsActive()):?>
            <?php 
                 $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
                 $_img = $cur_category->getImageUrl();  
            ?>
            <li>
                            <a href="<?php echo $helper->getCategoryUrl($cat);?>">
                                 <img src="<?php echo $_img?>" title="$cat->getName()"/>
                                 <cite><?php echo $cat->getName();?></cite>
                            </a>
                    </li>
            <?php endif?>

<?php endforeach;?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:28:01+00:00Added an answer on May 24, 2026 at 11:28 am

    Please try to use following code.
    Main idea is get main level category. For each category get children categories.

    <?php
          /* Get the categories that are active for the store */
          $_main_categories=$this->getStoreCategories();
    
          /* Get the current category the user is in */
          $_current_category=$this->getCurrentCategory();
    
          /* Get the current category path */
          $_categorypath = $this->getCurrentCategoryPath();
    ?>
    
        <?php if ($_main_categories): ?>
            <div class="box normal-nav">
                <div class="box-top">
                </div>
                <div class="box-content">
                        <ul>
                            <?php
                                /* This bit cycles through the categories - setting the next one to current */
                                foreach ($_main_categories as $_main_category):
                                    if($_main_category->getIsActive()):
                                        $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
                                        $layer = Mage::getSingleton('catalog/layer');
                                        $layer->setCurrentCategory($cur_category);
                            ?>
    
                                        <li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a>
    
                                            <?php $_maincategorylisting=$this->getCurrentCategory()?>
    
                                            <?php $_categories=$this->getCurrentChildCategories()?>
    
                                            <?php if($_categories->count()): ?>
                                                <ul class="subcategory">
                                                    <? foreach ($_categories as $_category):?>
                                                       <? if($_category->getIsActive()):
                                                              $cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
                                                              $layer = Mage::getSingleton('catalog/layer');
                                                              $layer->setCurrentCategory($cur_subcategory);
                                                       ?>
    
                                                              <li><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></li>
                                                       <? endif;?>
    
                                                     <?endforeach?>
    
                                                </ul>
                                                <?php $layer->setCurrentCategory($_current_category);  ?>
    
                                            <? endif; ?>
                                        </li>
    
                                 <?php endif; ?>
    
                            <?php endforeach; ?>
                        </ul>
                    </div>
                    <div class="box-bottom">
    
                    </div>
            </div>
        <?php endif;  ?>
    

    Added later:

    If apply fix for your code is look like following:

        <?php
            $_category  = $this->getCurrentCategory();
            $collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
            $helper     = Mage::helper('catalog/category');
        ?>
       <ul>
        <?php foreach ($collection as $cat):?>
                <li>
                    <a href="<?php echo $helper->getCategoryUrl($cat);?>">
                        <cite><?php echo $cat->getName();?></cite>
                    </a>
                    <?php $childLevel2Category = Mage::getModel('catalog/category')->getCategories($cat->entity_id); ?>
                    <ul>
                        <?php foreach ($childLevel2Category as $catLevel2) { ?>
                            <li>
                                <a href="<?php echo $helper->getCategoryUrl($catLevel2);?>">
                                    <cite><?php echo $catLevel2->getName();?></cite>
                                </a>
                            </li>
                        <?php } ?>
                    </ul>
                </li>
    <?php endforeach;?>
       </ul>
    

    If you need more level (more sub-dir) rewrite this construction using recursive function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display data from database in DataGridView...This is my code...Its not working...Can
I edited my wordpress page to only display posts from certain categories. This works,
I'm new to PHP and I want this code <option value= disabled=disabled>-------------</option> to be
Why this code don't work,when i want run this code vwd 2008 express show
I want to add this code: <link rel=stylesheet type=text/css href=css/global.css /> <!--[if lt IE
I have this code in my controller and want to test this code line
I want to make this 1332251639632 to this 1332251639 I try this code, but
What I want is this What I am getting is this My code is
I'm getting a segmentation fault everytime i want to run this code : from
I want to code this part of a VB6 application in c#. How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.