<h2>............................. Top Categories .............................</h2>
<?php
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('top_category',1)
->addIsActiveFilter();
foreach($categories as $_category)
{
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', $_category->getId())
->addAttributeToSort('created_at', 'desc');
foreach($_productCollection as $_topproduct)
{
$modell = Mage::getModel('catalog/product');
$topproduct_id = $_topproduct->getId();
$_topproduct = $modell->load($topproduct_id);
$_img=Mage::getModel('catalog/product')->load($topproduct_id);
?>
<div class="top-category-product">
<div class="top-category-product-name"><?php echo $_topproduct->getName(); ?></div>
<div class="top-category-product-image"><a href="<?php echo $_topproduct->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')->init($_img, 'image')->resize(200,200); ?>"></a></div>
</div>
<?php
}
}
?>
OR
<?php
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('top_category',1)
->addIsActiveFilter();
foreach($categories as $_category)
{
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->setOrder('created_at', 'DESC')
->addCategoryFilter($_category);
foreach($_productCollection as $_topproduct)
{
$topproduct_id = $_topproduct->getId();
$modell = Mage::getModel('catalog/product');
$_topproduct = $modell->load($topproduct_id);
$_img=Mage::getModel('catalog/product')->load($topproduct_id);
?>
<div class="top-category-product">
<div class="top-category-product-name"><?php echo $_topproduct->getName(); ?></div>
<div class="top-category-product-image"><a href="<?php echo $_topproduct->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')->init($_img, 'image')->resize(200,200); ?>"></a></div>
</div>
<?php
}
}
?>
Or For Distinct Values
<?php
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('top_category',1)
->addIsActiveFilter();
foreach($categories as $_category)
{
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->setOrder('created_at', 'DESC')
->addCategoryFilter($_category);
foreach($_productCollection as $_topproduct)
{
$topproduct_id[] = $_topproduct->getId();
}
}
$TopProIdArr = array_unique($topproduct_id);
foreach($TopProIdArr as $TopProId){
$modell = Mage::getModel('catalog/product');
$_topproduct = $modell->load($TopProId);
$_img=Mage::getModel('catalog/product')->load($TopProId);?>
<div class="top-category-product">
<div class="top-category-product-name"><?php echo $_topproduct->getName(); ?></div>
<div class="top-category-product-image"><a href="<?php echo $_topproduct->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')->init($_img, 'image')->resize(200,200); ?>"></a></div>
</div>
<?php }?>
No comments:
Post a Comment