如何在Magento中展示特定类别的新产品?

时间:2013-10-31 15:45:59

标签: magento

如何在magento中显示特定类别的新产品,只显示其图像,名称和描述?是否有可能将其添加到时事通讯上?

2 个答案:

答案 0 :(得分:1)

请使用以下代码。设置news_from_datenews_to_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() );

}

Example

答案 1 :(得分:0)

<?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