?
Solved

Echo subcategory description in navigation menu Magento

Posted on 2013-01-09
9
Medium Priority
?
1,422 Views
Last Modified: 2016-03-02
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
Comment
Question by:rafique12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:rafique12
ID: 38762471
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
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38762480
I dont think you have any other alternate solution
0
Independent Software Vendors: 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!

 
LVL 26

Expert Comment

by:EddieShipman
ID: 38762981
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
 

Author Comment

by:rafique12
ID: 38763046
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
 
LVL 26

Accepted Solution

by:
EddieShipman earned 2000 total points
ID: 38764156
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
 

Author Comment

by:rafique12
ID: 38764460
Thankyou for the link, very close to a solution now as the subcategory description is showing.

I will accept your answer...
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38764601
I thnk this was the key:
Mage::getModel( 'catalog/category' )->load( $child );

Open in new window

0
 

Author Comment

by:rafique12
ID: 38764676
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question