2

大家好,我想在我的 magento 1.7.1 安装的主页上显示 4 个流行的产品。(我可以通过将它们归入一个类别来选择)。

我通过创建一个名为popularhome 的隐藏类别并在其中添加了4 个产品来进行设置。

我已通过使用以下方法将其包含在我的主页模板中的静态块中:

{{block type="catalog/product_list" column_count="4" category_id="17" template="catalog/product/listhome.phtml"}}

我的 listhome.phtml 模板如下所示:

<div class="row popularproducts">

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<div class="alert fade in">
  <a class="close" data-dismiss="alert">×</a>
  <?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?php $_iterator = 0; ?>
    <?php else: ?>
    <?php // Grid Mode ?>
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
            <?php endif ?>
            <div class="c3">
            <?php if(($i-1)%$_columnCount==0): ?><?php elseif($i%$_columnCount==0): ?><?php endif; ?>
                <div class="thumbnail">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image thumbnail"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>

                <div class="caption">
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                    <?php endif; ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                </div>
                </div>
                </div>

            <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>


        <?php endif ?>
        <?php endforeach ?>
    <?php endif; ?>


<?php endif; ?>

</div>

但是,这仅显示了 4 种产品中的 2 种,但我不知道为什么?有人看到我缺少的东西吗?

谢谢!

4

1 回答 1

1

首先,您需要检查您希望出现在类别页面中的产品,

他们真的属于那个类别吗?

之后确保Backend > Manage Categories > Edit categories > Display settings >

Anchor = yes然后重新索引您的目录。

要验证您需要交叉检查 catalog_category_product 和 catalog_category_product_index。

如果类别 id 和产品 id 在这些表中正确映射,那么您应该很高兴。

希望这对你有帮助!

于 2013-09-18T14:39:23.000 回答