Displaying Category Page in Magento: A Comprehensive Guide
As a developer working with Magento for over a decade now, I often receive queries from beginners about displaying categories on their homepage. In this post, we’ll walk through the process of displaying active categories using the default theme and layout.
Understanding the Current Configuration
Your current configuration uses the catalog/product_new block type to display new products in your home page layout. This block is designed to showcase newly added products in your store. However, you want to display active categories instead.
The Goal: Display Active Categories on Homepage
The primary objective here is to replace the product_new block with a category listing block that will display all the active categories set up in the admin panel.
Step-by-Step Solution
1. Create a New XML Layout Update File
First, we need to create a new layout update file to override the default home page layout.
Navigate to: app/design/frontend/default/your-theme/layout
Create a new file called catalog.xml.
<layout version="0.1.0">
<default>
<reference name="content">
<block type="catalog/category_new" name="home.catalog.category.new" template="catalog/category/new.phtml"/>
</reference>
</default>
</layout>
In this file, we are replacing the catalog/product_new block with a new catalog/category_new block. This block is specifically designed to display categories.
2. Create a New Category Template
Next, you need to create the PHTML template file for your category listing.
Navigate to: app/design/frontend/default/your-theme/template/catalog/category
Create a new file called new.phtml.
<div class="category-products">
<ul class="products-grid products-grid--max-3-col list">
<?php foreach ($this->getCurrentCategory()->getAllProducts() as $_product): ?>
<li class="item item-product">
<?php /* @escapeNotVerified */ echo $this->getProductImage($_product, 'category_page_list') ?>
<div class="item-info">
<h3 class="item-title"><a href="<?php echo $this->getProductUrl($_product) ?>"><?php echo $_product->getName() ?></a></h3>
<?php /* @escapeNotVerified */ echo $_helper->productAttribute($product, $_product, 'brand') ?>
<div class="price-box">
<?php if ($block->hasPrice($_product)): ?>
<span class="regular-price" id="product-price-<?php /* @escapeNotVerified */ echo $_product->getId() ?>">
<?php /* @escapeNotVerified */ echo $this->__('Call for Price') ?>
</span>
<?php else: ?>
<p class="no-rate">
<?php echo $this->__('Out of stock') ?>
</p>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
This PHTML file lists all the products in the current category.
3. Set Up Your Category Listing
In your admin panel, navigate to Catalog > Categories. Make sure the categories you want to display are set as active and have “Include in Navigation Menu” checked under the Display Settings tab.
Conclusion: Displaying Magento Categories on Homepage
By following these steps, you should now see your active categories displayed on the homepage of your Magento store. The new block we added (catalog/category_new) will list all the active categories set up in the admin panel.
Remember to refresh your cache after making changes to the layout and template files.
If you’re looking for more advanced customization options or need help with any other Magento development tasks, feel free to check out our Magento Development Services at Laravel Company. We offer a range of services from theme creation to complex module development to ensure your e-commerce platform runs smoothly.
Happy coding!