如何编写在 magento 中显示类别的自定义面板

发布于 2024-10-05 19:15:07 字数 2349 浏览 3 评论 0原文

我有一个名为“热门产品”的类别。我希望将其显示在我主页的面板中。在 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 技术交流群。

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

发布评论

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

评论(2

扛起拖把扫天下 2024-10-12 19:15:07

我什至不会使用类别,而是使用此扩展:
特色产品

I wouldn't even use a category but this extension instead:
Featured Products

鹿港小镇 2024-10-12 19:15:07

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)并删除行,

<?php echo $this->getToolbarHtml() ?>

并删除输出“列表模式”的整个 if 块...基本上是 if 语句

    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>

,您应该只在其中包含“网格模式”代码。

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

<?php echo $this->getToolbarHtml() ?>

and remove the entire if-block that outputs the "list mode"... basically the if statement

    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>

and you should only have the "grid mode" code in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文