在带有图像缩略图的Magento导航菜单中显示子类别描述

时间:2012-12-18 11:30:29

标签: php magento

我有一个垂直导航菜单,显示父类别和子类别,其中包含图像缩略图和标题。我还想在子类别名称下面显示每个子类别的简短描述。目前,导航显示了列表中父类别foreach子类别的描述。

如何更改此内容?

这是代码:

    <?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" id="dcjq-vertical-mega-menu"> 
<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">                                 
<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 class="media">
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<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); ?>
<!-- Show image -->
<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>

<!-- End Show image-->

<!-- Show sub category Description -->
<li id="menu-item-4" class="pull-right">
<?php break; } ?>
<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>
</li> 
<!-- End show category Description -->
</ul> 
<div class="clearer"></div>
<!-- end of subcats -->
<?php endforeach; ?> 
</li> 
<?php endif; ?>  
</ul> 
<!-- end of parent cats -->
<?php endforeach; ?> 
</li> 
</ul> 
</ul> 
</li> 
</ul>
</div> 
<?php endif; ?>
<!--- Close 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 -->

我尝试更改此行:

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

对此:

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

但没有快乐!

欢迎任何帮助......

1 个答案:

答案 0 :(得分:0)

此代码适用于希望执行相同操作的任何人。您需要调整样式并编辑foreach循环以满足您的需求。

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>

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

<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<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); ?>
<!-- Show image -->
<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>

<!-- End Show image-->

<!-- Show sub category Description -->

<?php break; } ?>
<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>

<!-- End show category Description -->

<!-- end of subcats -->
<?php endforeach; ?> 

<?php endif; ?>  

<!-- end of parent cats -->
<?php endforeach; ?> 

<?php endif; ?>
<!--- Close Navigation Menu -->


<!--- Closed Navigation Menu -->