类别列表在类别页面上不起作用 - Magento
首先,我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您在
endforeach
之后缺少标记。
看一下你的 html 源代码。您可能会发现所有内容都在页面中,只是嵌套在
标记内,因此浏览器不会呈现它。
如果我是对的,这应该会为您显示内容(请注意末尾附近的
标签):
It looks like you are missing the
</ul>
tag after yourendforeach
.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):我建议您使用 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.转到管理->cms->页面->主页->设计->自定义设计->添加此代码
Go to Admin ->cms->pages->home page->design->custom design ->Add this code