Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1469
  • Last Modified:

Echo subcategory description in navigation menu Magento

I'm trying to find a way to show the short description for subcategories in Magento nav menu.

So far I have used this:

<?php echo $this->htmlEscape($_subcategory->getDescription()) ?>

Open in new window


But nothing shows. I have also changed it to this:

<?php echo $this->htmlEscape($_category->getDescription()) ?>

Open in new window


Which shows the parent category description.

Does any know how to do this? If you are willing to share I'd be very grateful.
0
rafique12
Asked:
rafique12
  • 4
  • 3
  • 2
1 Solution
 
rafique12Author Commented:
Thankyou for the response,

Yes I had followed this tutorial but my code is setup differently. I am using a vertical flyour menu (similar to Amazon) with parent categories which flyout to show subcategories with a thumbnail and (hopefully) subcategory description.

However, at the moment I can only get the description of the parent category to show foreach subcat which is very frustrating...

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<div class="left-nav-vertical visible-desktop visible-tablet hidden-phone" id="nav-vertical">
<ul class="nav nav-tabs-left"> 
<li class="dropdown open visible-desktop visible-tablet hidden-phone" id="left"> 
<a class="dropdown-toggle"><?php echo $this->__('Shop by Department') ?><b class="caret"></b></a> 
<ul class="dropdown-menu"> 
<div class="dcjq-vertical-mega-menu">                                  
<ul id="mega" class="menu"> 
<!--Top Category--> 
<?php foreach($_categories as $_category): ?> 
<li id="menu-item-1">
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?></a>
<ul> 
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<?php foreach($_subcategories as $_subcategory):$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_subcategory)->addAttributeToSelect('small_image');$products->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(1);$products->load();?> 
<!-- SubCategory--> 
<ul> 
<li id="menu-item-19">
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>" class="pull-right">
<span><p class="product-name"><?php echo $_subcategory->getName() ?></p> </a> 
<?php foreach($products as $product) { ?>
<?php $cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category); ?>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>" class="pull-left">
<img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(50, 50); ?>" class="static-thumbs" width="50" height="50" alt="<?php echo $_subcategory->getName() ?>" /></a>
<li id="menu-item-4" class="pull-right">
<em><?php echo $this->getCurrentCategory()->getDescription() ?></em></span>
<?php break; } ?>
</li> 
</ul> 
<div class="clearer"></div>
<!-- end of subcats -->
<?php endforeach; ?> 
</li> 
<?php endif; ?>  
</ul> 
<!-- end of parent cats -->
<?php endforeach; ?> 
</li> 
</ul> 
</div> 
</ul> 
</li> 
</ul>
</div> 
<?php endif; ?>
<!--- Closed Navigation Menu -->

<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
  jQuery('#mega').dcVerticalMegaMenu({
    rowItems: '1',
    speed: 'fast',
    effect: 'slide',
    direction: 'right'
  });
});
</script>
<!--- Closed Navigation Menu -->

Open in new window

0
 
sivagnanam chandrakanthTechnical LeadCommented:
I dont think you have any other alternate solution
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Eddie ShipmanAll-around developerCommented:
Did you try:
<?php echo $this->htmlEscape($_subcategory->getName()) ?>

Open in new window


Essentially the Name is the Short Description. The categories model doesn't have a ShortDescription.

Also, check this out:
http://fishpig.co.uk/blog/category-navigation-listings-in-magento.html
0
 
rafique12Author Commented:
I have the name already but are you saying their isn't a way to show the description for a sub category - only the name?

If I include:

<?php echo $this->htmlEscape($_subcategory->getName()) ?>

Open in new window


I just get the name and not the description.

I'm not sure if I may have misunderstood your answer.
0
 
Eddie ShipmanAll-around developerCommented:
You said "show the short description" There is no "Short Description" attribute for a category, only Name and Description.

Maybe this post will help you figure it out:
http://stackoverflow.com/questions/7201433/magento-displays-subcategories-description-on-category-list-phtml?rq=1
0
 
rafique12Author Commented:
Thankyou for the link, very close to a solution now as the subcategory description is showing.

I will accept your answer...
0
 
Eddie ShipmanAll-around developerCommented:
I thnk this was the key:
Mage::getModel( 'catalog/category' )->load( $child );

Open in new window

0
 
rafique12Author Commented:
Stilll a slight issue that I need to figure out as it loads every description foreach category.

instead of one per category. I think its the way my code is setup...

<span><em>
<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
        <?php foreach( $children as $child ): ?>
            <?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
            <li><?php echo $_child->getDescription(); ?></li>
        <?php endforeach; ?>
</em></span>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now