0

ホバーしたときに親カテゴリとサブカテゴリを画像のサムネイルとタイトルとともに表示する垂直ナビゲーション メニューがあります。サブカテゴリ名の下に、各サブカテゴリの簡単な説明も表示したいと思います。現在、ナビゲーションには、リスト内の各サブカテゴリの親カテゴリの説明が表示されています。

これを変更するにはどうすればよいですか?

コードは次のとおりです。

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

しかし、喜びはありません!

どんな助けでも大歓迎です...

4

1 に答える 1

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 -->
于 2013-01-10T22:02:08.003 に答える