如何编写在 magento 中显示类别的自定义面板
我有一个名为“热门产品”的类别。我希望将其显示在我主页的面板中。在 magento 中执行此操作的最佳方法是什么?
** 编辑 **
谢谢 sdek,我现在有以下内容。在主页/设计中。
<block type="catalog/product_list" category_id="13" template="catalog/product/featured.phtml"/>
它正在展示产品。但是我有以下问题。 - 它没有显示来自category_id 13的产品,看起来这个值没有被传递 - 它只显示 2 个产品。我希望显示全部。
精选.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<h2>Featured Products </h2>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="product-grid">
<?php endif ?>
<li class="<?php if(($i-1)%$_columnCount==0): ?> first<?php else: ?> last<?php endif; ?>">
<a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" >
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(85); ?>" class="product-img" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="padding-bottom:20px; margin-bottom:20px;" />
</a>
<p><strong><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></strong>
<?php echo $_product->getShortDescription(); ?></p>
<?php echo $this->getPriceHtml($_product, true) ?>
<a href="<?php echo $_product->getProductUrl() ?>" class="more">More details</a>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?
I have a category called "Top Products". I wish to display this in a panel on my home page. What is the best way to do this in magento.
** edit **
Thanks sdek, i now have the following. In Home Page / Design.
<block type="catalog/product_list" category_id="13" template="catalog/product/featured.phtml"/>
And it is displaying products. However i have the following issues.
- it's not displaying products from category_id 13, It seems like this value is not being passed thru
- it's only display 2 products. I wish to display all.
featured.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<h2>Featured Products </h2>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="product-grid">
<?php endif ?>
<li class="<?php if(($i-1)%$_columnCount==0): ?> first<?php else: ?> last<?php endif; ?>">
<a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" >
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(85); ?>" class="product-img" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="padding-bottom:20px; margin-bottom:20px;" />
</a>
<p><strong><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></strong>
<?php echo $_product->getShortDescription(); ?></p>
<?php echo $this->getPriceHtml($_product, true) ?>
<a href="<?php echo $_product->getProductUrl() ?>" class="more">More details</a>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我什至不会使用类别,而是使用此扩展:
特色产品
I wouldn't even use a category but this extension instead:
Featured Products
Clockworkgeek 提到的特色产品扩展是一个好主意。但如果您不喜欢该选项,最简单的方法是将其添加到您的主页 cms 中
{{block type="catalog/product_list"category_id="YOUR_CAT_ID" template="catalog/product/YOUR_MODIFIED_COPY_OF_LIST.phtml"}}
然后复制 app/design/frontend///template /catalog/product/list.phtml(我在上面将其称为 YOUR_MODIFIED_COPY_OF_LIST.phtml)并删除两行,
并删除输出“列表模式”的整个 if 块...基本上是 if 语句
,您应该只在其中包含“网格模式”代码。
The Featured Products extension mentioned by clockworkgeek is a good idea. But if you don't like that option the easiest thing to do is to add this in your home page cms
{{block type="catalog/product_list" category_id="YOUR_CAT_ID" template="catalog/product/YOUR_MODIFIED_COPY_OF_LIST.phtml"}}
And then make a copy of app/design/frontend///template/catalog/product/list.phtml (I refered to it above as YOUR_MODIFIED_COPY_OF_LIST.phtml) and remove the two lines that say
and remove the entire if-block that outputs the "list mode"... basically the if statement
and you should only have the "grid mode" code in there.