Tag » Posts Tagged ‘Category’

How to get the child block object in .phtml file in Magento

Magento

In one of our projects, the requirement was to have a different layout for some category pages. So, we decided to use a different template file for these categories. We added the following code in the “Custom Layout Update” field for these categories in admin.

 <reference name="category.products">
    <action method="setTemplate">
        <template>catalog/category/custom-category.phtml</template>
    </action>
</reference>

These category pages need to show the products in a different layout.

Continue reading »

How to find the position of a product in a Magento category

Magento

In Magento you can set the position of the products in a category from Magento admin by following the path Admin >> Catalog >> Categories >> Manage Categories >> Edit a category >> Set the position of the products in the “Category Products” tab.

Let see how we can find the position of a product on the product detail page:


$catId = Mage::registry('current_product')->getCategoryId();
$category = Mage::getModel('catalog/category')->load($catId);
$productPositions = Mage::getResourceModel('catalog/category')->getProductsPosition($category); // This returns all product ids with their position
echo $productPositions[$_product->getId()]; //Print the product postion

Continue reading »

How to display sub-categories on a Category Page

Magento

In one of my project we had a two level category hierarchy. Clicking on the top level category displayed a promotional banner and the sub-categories. The second level category page displayed the products. In this post we will discuss how we can display the subcategories on a category page. We are not going to create any new module.

STEP 1: Create a PHTML file

First we create a phtml file {{MAGENTO_ROOT}}\app\design\frontend\rwd\mytheme\template\catalog\category\subcategories.phtml

Continue reading »

How to display products from a category in a CMS static block

Magento

There might have been a situation when you would have created a special category like “Sale Products” or “Featured Products”… and you had wanted to display products from these categories on some page like Home Pages using the CMS static block.

In order to achieve this you may create a CMS static block and add the following segment of code:


{{block type="catalog/product_list" name="product_list" category_id="2" column_count="4" template="catalog/product/list.phtml" }}

This will display the products listing page as a block on the page.

Continue reading »

Back to top