Snippets with the tag: category

Current category name

Description

Get the current category name

Code

Mage::registry('current_category')->getName();

Display new products from specific category on home page

Description

code to display new products from a particular category on home page

Code

{{block type="catalog/product_list" category_id="10" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

Get categories products ordered by number of sales

Description

Get categories products ordered by number of sales

Code

$categoryId = 1; 
$category = Mage::getModel('catalog/category')->load($categoryId); 
$products = Mage::getResourceModel('reports/product_collection') 
          ->addOrderedQty() 
          ->addAttributeToSelect('*') 
          ->setOrder('ordered_qty', 'desc') 
          ->addCategoryFilter($category);

Get all top level categories

Description

Get all of the top level categories. Usually, the first base category added will have the id of 2.

Code

$defaultCategoryId = 2; 
$topLevelCats = Mage::getModel('catalog/category') 
->getCollection() 
->addAttributeToSelect('path','name','id') 
->addAttributeToFilter('parent_id', $defaultCategoryId) 
->setOrder('position', 'ASC');

Check if RSS is enabled

Description

Check if RSS is enabled

Code

Mage::getStoreConfig('rss/catalog/category');

Category navigation listings

Description

Make sure the block that you’re working on is of the type catalog/navigation. If you’re editing catalog/navigation/left.phtml it should be okay.

Code

helper('catalog/category') ?> getStoreCategories() ?> 0): ?>

Load products by category ID

Description

Load products by category ID, for example 12.

Code

$_category = Mage::getModel('catalog/category')->load(12);
$_productCollection = $_category->getProductCollection();
if($_productCollection->count()) {
    foreach( $_productCollection as $_product ):
        echo $_product->getProductUrl();
        echo $this->getPriceHtml($_product, true);
        echo $this->htmlEscape($_product->getName());
    endforeach;
}