如何在Magento中显示特定类别的新产品?
如何在magento中显示特定类别的新产品,并仅显示其图像、名称和描述?是否可以将其添加到新闻稿中?使用下面的代码。设置您的如何在Magento中显示特定类别的新产品?,magento,Magento,如何在magento中显示特定类别的新产品,并仅显示其图像、名称和描述?是否可以将其添加到新闻稿中?使用下面的代码。设置您的news\u from\u date和news\u to\u date日期和CategoryId 它刚刚创建了它,并用准备好的产品进行了测试: $collection = Mage::getModel('catalog/product') ->getCollection() ->addCate
news\u from\u date
和news\u to\u date
日期和CategoryId
它刚刚创建了它,并用准备好的产品进行了测试:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addCategoryFilter(Mage::getModel('catalog/category')->load(3))
->addAttributeToSelect(array('name', 'sku', 'description', 'small_image', 'news_from_date', 'news_to_date', 'category_id'))
->addAttributeToFilter('news_from_date',array('date' => true, 'gteq' => '2013-05-03'))
->addAttributeToFilter('news_to_date', array('date' => true, 'lteq' => '2013-11-25') )
;
foreach ($collection as $product)
{
var_dump( $product->getName() );
var_dump( $product->getDescription() );
var_dump( $product->getNewsFromDate() );
var_dump( $product->getNewsToDate() );
}
在这里输入代码
感谢您的及时回复,我应该将此代码放在哪里以及如何使用此代码它是php代码,因此您可以将其作为单个.phtml
文件添加到magentoapp/design/frontend/…
上下文中。如果要将其用作新闻稿内容,可能必须为此创建块
,以便将脚本输出嵌入新闻稿cms编辑器中。。。但我不知道,到底怎么做。。。
<?php
$categoryid = 12;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /></a> <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
enter code here