Magento Forum

Get parent categories if children have none
 
aidin3000
Jr. Member
 
Total Posts:  2
Joined:  2011-10-15
 

I have the following code to display children categories within current category, however if there are no children categories, it will return blank.

How can I get the parent category links (one level up) if no children exist for the current category.

<?php
/**
 * Block of categories
 */
?>

<?php
    $theme 
$this->helper('ultimo');
    
$visibilityClass $theme->getCfg('category/categories_hide_on_mobile') ? 'hide-below-768' '';
    
$_helper    $this->helper('catalog/output');
    
$_category  $this->getCurrentCategory();
?>
<?php 
if ($theme->getCfg('category/categories')): ?>
 
<div class="block block-vertnav<?php echo " $visibilityClass"; ?>">
     <
div class="hdr-block-title">
        <!--<
strong><span><?php echo $this->__('Categories'); ?></span></strong>-->
        <
h1><?php echo $_helper->categoryAttribute($_category$_category->getName(), 'name'?></h1>
    </
div
    
<!--
        <
ul class="accordion vertnav clearer">
            
<?php echo $this->renderCategoriesMenuHtml(TRUE0,'level-top'); ?>
        
</ul>
    </
div>
     --> 
    
<?php
    $object 
= new Mage_Catalog_Block_Navigation();
    
$actualCategoryId $object->getCurrentCategory()->getId();
    
$actualCategory Mage::getModel('catalog/category')->load($actualCategoryId);
    
$subCategories explode(','$actualCategory->getChildren());
    
    if (
$_category->hasChildren()) { ?>
        
<div class="block-content block block-layered-nav">
        <
dl class="narrow-by-list">
        <
dt class="odd">Shop <?php echo $_helper->categoryAttribute($_category$_category->getName(), 'name'?></dt>
        <
dd class='odd'><ol>
        
<?php
            
foreach ( $subCategories as $subCategoryId )
            
{
                $category 
Mage::getModel('catalog/category')->load($subCategoryId);
                if ( 
$category->getIsActive() )
                
{
                    
echo '<li><a href="'.$category->getURL().'">'.$category->getName().'</a></li> ';
                
}
            }
            
echo "</ol></dd></dl></div>";
        
?>
    <?php } ?>
         
    
</div>

<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top