我是Magento的新手。目前我正在做一个主题。在这方面,我想展示所有的产品从特色类别。为此,我在里面做了一个名为featred.phtml
的文件CCD_ 2。featured.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-->
现在,我得到了所有的特色产品。之后,我想在我的标题中显示所有特色产品。为此,我在page.xml(app/design/frontend/mytheme/default/layout)
中制作了一个类似的块
<block type="catalog/product_featured" name="product.featured" as="topSlider" translate="label">
<label>Page Slider</label>
<action method="setElementClass"><value>top-slider</value></action>
</block>
现在我把header.phtml
中的那个块称为
<?php echo $this->getChildHtml('topSlider'); ?>
但在所有这些之后,我在主页或任何其他页面上都看不到任何特色产品。那么,有人能告诉我如何解决这个问题吗?任何帮助和建议都将非常可观。感谢
会有几个问题:
- 您是否创建了块类
Mage_Catalog_Block_Product_Featured
?1.a你可以通过setTemplate in layout.xml
分配模板,我希望你在块类中这样做 - 在什么
<reference> tag (should be header)
中,您通过上面的布局声明添加块 - 是
layout.xml active at all
吗 - 你的
design package set in System->Configuration
(我会从"基地"开始,意思是基地/你的主题)吗 - 你的模板中的代码真的被调用了吗?也许它只是一个
empty collection