Magento在主页上按价格对产品进行排序

Magento在主页上按价格对产品进行排序,magento,magento-1.8,Magento,Magento 1.8,我使用的是现代模板,主页上有一个新的.phtml。这使我在主页上的所有产品。我的产品按价格分类有问题。我把所有可以对任何一种产品进行分类的观点都改为按价格分类。但这似乎不起作用 我在另一页上还发现: 并将其添加到顶部,然后将if语句更改为: <?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> 致: 我还不太明白这是怎么回事。我得到

我使用的是现代模板,主页上有一个新的.phtml。这使我在主页上的所有产品。我的产品按价格分类有问题。我把所有可以对任何一种产品进行分类的观点都改为按价格分类。但这似乎不起作用

我在另一页上还发现:

并将其添加到顶部,然后将if语句更改为:

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

致:



我还不太明白这是怎么回事。我得到的只是简短的描述和价格。所有其他属性都没有显示。

我在代码中发现了错误

$model = Mage::getModel('catalog/product');
$collection = $model->getCollection();
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('small_image');
$collection->addAttributeToSelect('short_description');
$collection->addAttributeToSort('price', 'ASC');
$collection->load();
我发现在代码的更深处,它调用的是小图像,而不是基本图像

我还发现,如果你用正确的名称命名属性,那么它会有所帮助。将标题更改为名称

<?php if (($_products = $collection) && $_products->getSize()): ?>
$model = Mage::getModel('catalog/product');
$collection = $model->getCollection();
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('small_image');
$collection->addAttributeToSelect('short_description');
$collection->addAttributeToSort('price', 'ASC');
$collection->load();