类别列表不适用于类别页面 - Magento

时间:2010-09-18 15:52:35

标签: php magento navigation e-commerce categories

首先,我是Magento的新手,所以请详细解释一下是否可以提供帮助。

我使用了以下代码:

  <div class="left-nav-inner">  
    <h3 id="products">Products</h3>
    <h4>Shop by:</h4>
    <ul id="product-menu">

<?php
/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();

/* Get the current category the user is in */
$_current_category=$this->getCurrentCategory();

/* Get the current category path */
$_categorypath = $this->getCurrentCategoryPath();
?>
<?php
if ($_main_categories):
    /* This bit cycles through the categories - setting the next one to current */
    foreach ($_main_categories as $_main_category):
      if($_main_category->getIsActive()):                             
           $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
           $layer = Mage::getSingleton('catalog/layer');
           $layer->setCurrentCategory($cur_category);     

/* Write the main categories */           
?>                
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li>   


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting=$this->getCurrentCategory()?>                        
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>


<?php /* This resets the category back to the original pages category
****     If this is not done, subsequent calls on the same page will use the last category
****    in the foreach loop
*/   ?>
<?php $layer->setCurrentCategory($_current_category);  ?> 
<?php endif; ?>   

<?php endif; ?>                                   

<?php         
endif;
endforeach; 
else:
?>
<p>$_main_categories array was empty.</p>
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
<?php endif; ?>
</div>

这会根据需要显示我左侧菜单上的列表,但是当我点击类别网址时,类别页面将不显示产品..

如果我删除了左列中的

,我可以显示产品

应用程序/设计/前端/默认/默认/布局/的catalog.xml

我使用以下代码完成了此操作:


类别默认布局


<catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>
    <remove name="left" />

如你所见,我添加了'删除名称=左'。

我需要左侧菜单,并在网站的每个页面上显示类别,我需要在点击类别时显示产品......

请帮忙。

3 个答案:

答案 0 :(得分:0)

我建议您使用Alan Storm的Layoutviewer来调试目标网址上发生的事情。您可以从this article下载它,请注意您需要创建自己的模块声明xml以插入app/etc/modules以激活模块。

答案 1 :(得分:0)

</ul>后的endforeach标记似乎丢失了。

查看您的html源代码。您可能会发现所有内容都在页面中,只是嵌套在<ul>标记内,因此浏览器无法呈现它。

如果我是对的,这应该为你显示(注意结尾附近的</ul>标签):

 <div class="left-nav-inner">  
    <h3 id="products">Products</h3>
    <h4>Shop by:</h4>
    <ul id="product-menu">

<?php
/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();

/* Get the current category the user is in */
$_current_category=$this->getCurrentCategory();

/* Get the current category path */
$_categorypath = $this->getCurrentCategoryPath();
?>
<?php
if ($_main_categories):
    /* This bit cycles through the categories - setting the next one to current */
    foreach ($_main_categories as $_main_category):
      if($_main_category->getIsActive()):                             
           $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
           $layer = Mage::getSingleton('catalog/layer');
           $layer->setCurrentCategory($cur_category);     

/* Write the main categories */           
?>                
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li>   


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting=$this->getCurrentCategory()?>                        
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>


<?php /* This resets the category back to the original pages category
****     If this is not done, subsequent calls on the same page will use the last category
****    in the foreach loop
*/   ?>
<?php $layer->setCurrentCategory($_current_category);  ?> 
<?php endif; ?>   

<?php endif; ?>                                   

<?php         
endif;
endforeach; 
?>
</ul><!-- See what I did here? -->
<?php
else:
?>

<p>$_main_categories array was empty.</p>
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
<?php endif; ?>
</div>

答案 2 :(得分:0)

转到管理员 - &gt; cms-&gt; pages-&gt;主页 - &gt; design-&gt;自定义设计 - &gt;添加此代码

ItemsSource