문제

<?php

    $categoryid = 64;

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

<?php } ?>
도움이 되었습니까?

해결책 3

<?php
foreach($this->getStoreCategories() as $_category)
{
    $cur_category=Mage::getModel('catalog/category')->load($_category->getId());
    $collectionnn = Mage::getModel('catalog/product')
                              ->getCollection()
                              ->joinField('category_id','catalog/category_product', 'category_id', 'product_id = entity_id',null, 'left')
                              ->addAttributeToSelect('*')
                              ->addAttributeToFilter('category_id',array('in' => $cur_category->getId()));        
                    foreach($collectionnn as $product)
                    {
                        echo "<a href=".$product->getProductUrl().">".$product->getName()."</a><br>";
                        break;
                    }
}            
?>

다른 팁

Try this

$category = Mage::getModel('catalog/category')->load(64);
$collection = $category->getProductCollection()->addAttributeToFilter('status', 1);
$collection->getSelect()->limit(1);
foreach($collection  as $product)
{
    echo "<a href=".$product->getProductUrl().">".$product->getName()."</a><br>";
}

Try following

$category=Mage::getModel('catalog/category')->load($category_id);
$products = $category->getProductCollection()
//->addAttributeToSelect('*') // add all attributes - optional
->addAttributeToSelect(array('name','entity_id','price','small_image','frontend_name'))
->setPageSize(1)
->setOrder('created_at', 'DESC'); //sets the order by created_at
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top