Answer the question
In order to leave comments, you need to log in
How to display product categories on the main page in Magento?
There are categories, there are products. I need to display the categories on the main page
Answer the question
In order to leave comments, you need to log in
Display a list of products from a specific category.
The easiest way is to use the standard {{block ...}}. Example:
The output template can be edited:
- remove the toolbar
- limit the output of the number of products
- remove links to the wishlist and compare, etc.
Display the list of categories. Example:
The contents of the file /app/design/frontend/default/default/template/catalog/category/list.phtml
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php
$open = $this->isCategoryActive($_category);
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if ($immagine = $this->getCurrentCategory()->getImageUrl()): ?>
<div style="float: left; padding-right: 30px; text-align: center;">
<div class="linkimage">
<p>
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="135" height="135" />
<?php echo $_category->getName()?>
</a>
</p>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php $_maincategorylisting = $this->getCurrentCategory(); ?>
<?php $_categories = $this->getCurrentChildCategories(); ?>
<div class="subcat-listing">
<ul class="subcat-products">
<?php foreach ($_categories as $_category): ?>
<?php if ($_category->getIsActive()): ?>
<?php $cur_category = Mage::getModel('catalog/category')->load($_category->getId()); ?>
<?php $layer = Mage::getSingleton('catalog/layer'); ?>
<?php $layer->setCurrentCategory($cur_category); ?>
<?php if ($_imageUrl = $this->getCurrentCategory()->getImageUrl()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<img src="<?php echo $_imageUrl ?>" width="auto" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<?php if ($_description=$this->getCurrentCategory()->getDescription()):?>
<p class="category-description"><?php echo $_description ?></</p>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question