Solved

Echo subcategory description in navigation menu Magento

Posted on 2013-01-09
9
1,356 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38762377
0
 

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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now