0

I'm very new for magento. I hire a company to create my magento website. however, there are some features that i 'd like to improve.

For displaying categories and subcategories in cms page, i found code that some kindly shared to others. But i don't know where or which file in ftp i should paste the code.

now : the page of subcategory shows only its name on left navigator. Expectation : the page shows both parent category and all subcategories, so the customers can link to other subcategories by clicking on side menu.

This is both for products page and other pages, for example, menu "about us" has 2 subcategories : history, our vision. when the user click subcategories "our vision", it will show "about us" , "history", and "our vision" on the left side bar.

I have captured my website as belows: parent category page ------> subcategory page

Thank you in advance.

Code i think it may be work. (in the fact, i would like it to appear only subcategories in current category)

<?php
$_helper = Mage::helper('catalog/category');
$categories = $_helper->getStoreCategories();

foreach ($categories as $_category) {
    $category = Mage::getModel('catalog/category')->load($_category->getId());
    $subcategories = $category->getChildrenCategories();
    ?>
    <dl>
        <dt><?php echo $this->htmlEscape($_category->getName()); ?></dt>
        <dd>
            <ol>
                <?php
                foreach ($subcategories as $_subcategory) {
                    echo '<li><a href="' . $_subcategory->getURL() . '">' . $_subcategory->getName() . '</a></li>';
                }
                ?>
            </ol>
        </dd>
    </dl>
    <?php

}
?>
  • Can you add the code which you want to paste? – Jaimin Sutariya Apr 24 '17 at 17:18
  • @JaiminSutariya I have added more information. Sorry for late reply. – Tuamtiam Apr 27 '17 at 18:04
0

I finally fixed it. go to app/design/frontend/default/YOURTEMPLATE/catalog/navigation/leftnav.phtml

And correct the code like this.

<?php
  $redirect_url = Mage::getUrl('customer/account/');
  $current_url = Mage::helper('core/url')->getCurrentUrl();
  if( $current_url != $redirect_url):?>
<div class="block left-categorys">
<?php
//     $currentCat = Mage::registry('current_category');
     $currentCat =Mage::getModel('catalog/layer')->getCurrentCategory(); 
    echo '<div class="block-title"><h2>'.$currentCat->getParentCategory()->getName().'</h2>
</div>';

    if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() ){
        $loadCategory = $currentCat;
    }else{
        $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
    }
    $subCategories = explode(',', $loadCategory->getChildren());  
    if(count($subCategories) > 1){
        echo '<div class="block-content left-categorys-container">';
        foreach ( $subCategories as $subCategoryId ){
            $cat = Mage::getModel('catalog/category')->load($subCategoryId);
            if($cat->getIsActive()){
                echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>';

            }
        }
        echo '</div>';
      }
   ?>
</div>
<?php endif ?>

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.