我一直在寻找这个答案的高低。如果有人能指出我正确的方向,我将非常感激。我想在侧边栏导航中显示子类别上的所有其他子类别。
作为一个例子......
INSTEON
当选择INSTEON的子类别(以INSTEON响应者为例)时 - 我仍然希望显示其他孩子(请参阅http://www.smarthome.com.au/insteon.html)。理想情况下,现在的孩子应该是大胆的,其他孩子应该是正常的。
我相信我需要编辑app / design / frontend / theme / subtheme / template / catalog / navigation / left.phtml
<!--Added by Brad - Get current category -->
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content">
<dl id="narrow-by-list2">
<!--Added by Brad - Display current category name -->
<dt><h2><?php echo $currentCategory->getName(); ?><?php echo $this->__('') ?></h2></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->escapeHtml($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<?php endif; ?>
非常感谢任何帮助。
答案 0 :(得分:0)
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $parent = $this->getCurrentCategory()->getParentCategory()->getId(); ?>
<?php $parent = Mage::getModel('catalog/category')->load($parent); ?>
<?php $siblings = explode(',', $parent->getChildren()); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav block-layered-nav--no-filters">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content toggle-content open">
<p class="block-subtitle block-subtitle--filter"><?php echo $this->__('Filter') ?></p>
<dl id="narrow-by-list2">
dt><?php echo $this->__('Category') ?></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>>
<?php echo $this->escapeHtml($_category->getName()) ?>
<span class="count">(<?php echo $_category->getProductCount() ?>)</span>
</a>
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<?php elseif(count($siblings > 1)): ?>
<div class="block block-layered-nav block-layered-nav--no-filters">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content toggle-content open">
<p class="block-subtitle block-subtitle--filter"><?php echo $this->__('Filter') ?></p>
<dl id="narrow-by-list2">
dt><?php echo $this->__('Category') ?></dt>
<dd>
<ol>
<?php foreach($siblings as $sibling_id): ?>
<?php $sibling = Mage::getModel('catalog/category')->load($sibling_id); ?>
<li>
<a href="<?php echo $this->getCategoryUrl($sibling) ?>"<?php if ($this->isCategoryActive($sibling)): ?> class="current"<?php endif; ?>>
<?php echo $this->escapeHtml($sibling->getName()) ?>
<span class="count">(<?php echo $sibling->getProductCount() ?>)</span>
</a>
</li>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
答案 1 :(得分:-1)
只需使用
$parent_category_id = $this->getCurrentCategory()->getParentCategory()->getId();
获取父类别ID。然后
Mage::getModel('catalog/category')->load($parent_category_id);
加载整个父类别。有了它,您可以加载父类别的孩子(参见Get Child categories magento)。
- 编辑 -
<!--Added by Brad - Get current category -->
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<!-- My code -->
<?php $parent = $this->getCurrentCategory()->getParentCategory()->getId(); ?>
<?php $parent = Mage::getModel('catalog/category')->load($parent); ?>
<?php $siblings = explode(',', $parent->getChildren()); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Browse By') ?></span></strong>
</div>
<div class="block-content">
<dl id="narrow-by-list2">
<!--Added by Brad - Display current category name -->
<dt><h2><?php echo $currentCategory->getName(); ?><?php echo $this->__('') ?></h2></dt>
<dd>
<ol>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->escapeHtml($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ol>
</dd>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
</div>
</div>
<!-- this will only show if there are no child categories of current child (and there are siblings) -->
<?php elseif(count($siblings > 1)): ?>
<!-- show sibling categories if have any -->
<?php foreach($siblings as $sibling_id): ?>
<?php if($sibling_id == $currentCategory->getId()): ?>
<!-- CURRENT CATEGORY -->
<?php else: ?>
<!-- SIBLING CATEGORY -->
<?php $sibling = Mage::getModel('catalog/category')->load($sibling_id); ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>