Magento产品来自一个类别,当xml文件发生更改时不显示


Magento product from a category not showing when changes in xml file

我在Magento遇到了一个奇怪的问题。我想在我的标题中添加一个滑块,其中一个类别的所有产品都将显示在滑块中。为此,我刚刚创建了fetured.phtml文件,并在其中制作了类似的代码

<?php $cat_id = 35; ?>
<?php $category = Mage::getModel('catalog/category')->load($cat_id);?>
<?php $collection = $category->getProductCollection()->addAttributeToSort('position');?>
<?php Mage::getModel('catalog/layer')->prepareProductCollection($collection);?>
<?php  $i=0; foreach ($collection as $_product):?>
<?php if($i++%7==0): ?>
 <div class="container">
  <div id="da-slider" class="da-slider">
  <?php endif ?>
  <div class="da-slide">
    <h2 class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></h2>
    <p class="price"><?php echo $formattedSpecialPrice = Mage::helper('core')->currency($_product->getFinalPrice(),true,false);?></p>
    <p><?php echo $_product->_data['short_description']; ?> </p> <br />
    <a class="da-link" href="<?php echo $_product->getProductUrl() ?>">Shop Now</a>
    <div class="da-img"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(90, 90); ?>" width="120" height="120" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></div>
    <!--.da-img-->
   </div><!--.da-slide-->
   <?php endforeach ?>
    <nav class="da-arrows">
      <span class="da-arrows-prev"></span>
      <span class="da-arrows-next"></span>
    </nav><!--.da-arrows-->
  </div><!--#da-slider-->
 </div><!--.container-->

之后,由于我想在标题中显示产品,我转到了catalog.xml文件app/design/frontend/mytheme/default/layout/catalog.xml,在其中我制作了这样的

<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
  <label>Page Header</label>
    <block type="catalog/product_featured" name="catalog.product.featured" template="catalog/product/featured.phtml" />
      <action method="setElementClass"><value>top-container</value></action>
    </block>
 </block>

在这里,我这样做是为了在滑块的标题中显示受保护的产品类别。但它并没有展示这些产品。但如果我把代码改成

<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
      <label>Page Header</label>
        <block type="catalog/product_list" name="catalog.product.featured" template="catalog/product/featured.phtml" />
          <action method="setElementClass"><value>top-container</value></action>
        </block>

它在滑块中显示产品。有人能告诉我这里出了什么问题吗?任何帮助和建议都将是非常可观的。感谢

第一个代码没有显示产品的原因是您使用catalog/product_featured作为块类型
Magento试图从block文件夹中获取块文件,但失败了,因为block文件夹中没有Featured.php
当使用catalog/product_list作为块类型时,它会从块文件夹中找到List.php并显示结果
如果您想让第一个代码工作,只需在Block文件夹中创建一个名为Featured.php
的文件希望这能有所帮助。。