2013-10-31 111 views

回答

1

使用下面的代碼。設置您news_from_datenews_to_date日期和CategoryId

It've創建它剛纔並用事先準備好的產品進行了測試:

$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

+0

感謝您的及時答覆,我在哪裏可以放這段代碼,我將如何使用這段代碼 –

+0

這是php代碼,所以你可以在magento app/design/front中將它作爲單個'.phtml'文件添加結束/ ...'上下文。如果你使用它作爲新聞通訊的內容,也許你必須創建一個「塊」來將腳本的輸出嵌入到通訊cms編輯器中......但我不知道,如何完全做到這一點... –

+0

@StefanBrendle很好的解釋.. – Elavarasan

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 
相關問題