类别列表在类别页面上不起作用 - Magento

发布于 2024-09-24 03:53:40 字数 2772 浏览 2 评论 0原文

首先,我是 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>

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

如果删除以下内容中的左侧列,我可以显示产品:

app/ design/frontend/default/default/layout/catalog.xml

我使用以下代码执行此操作:


类别默认布局


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

如您所见,我添加了“删除名称=左”。

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

请帮助。

Firstly I am new to Magento, so please explain in detail if you can help.

I have used the following code:

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

This displays listings on my left menu as required however when I click the category urls the category page will not show the products..

I can get the products to show if I remove the left column within:

app/design/frontend/default/default/layout/catalog.xml

I did this with the following code:


Category default layout


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

As you can see I added the 'remove name=left'.

I need to have the left menu with the categories displaying on every page of the website and I need the products to show up when I click on the categories...

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾城月光淡如水﹏ 2024-10-01 03:53:40

看起来您在 endforeach 之后缺少 标记。

看一下你的 html 源代码。您可能会发现所有内容都在页面中,只是嵌套在

    标记内,因此浏览器不会呈现它。

如果我是对的,这应该会为您显示内容(请注意末尾附近的 标签):

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

It looks like you are missing the </ul> tag after your endforeach.

Take a look in your html source. You may find that everything is in the page, just nested inside the <ul> tag, so it doesn't get rendered by the browser.

If I'm right, This ought to show things up for you (notice the </ul> tag near the end):

 <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>
悲念泪 2024-10-01 03:53:40

我建议您使用 Alan Storm 的 Layoutviewer 来调试目标 url 上发生的情况。您可以从本文下载它,请注意,您需要创建自己的模块声明 xml 以插入到 < code>app/etc/modules 用于要激活的模块。

I would recommend that you use Alan Storm's Layoutviewer to debug what's happening on your target url. You can download it from this article, note that you will need to create your own module declaration xml to insert into app/etc/modules for the module to be activated.

生来就爱笑 2024-10-01 03:53:40

转到管理->cms->页面->主页->设计->自定义设计->添加此代码

<reference name="left">
    <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>

Go to Admin ->cms->pages->home page->design->custom design ->Add this code

<reference name="left">
    <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文