N
N
Nikolay Erofeev2014-11-18 07:29:28
CMS
Nikolay Erofeev, 2014-11-18 07:29:28

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

1 answer(s)
Y
Yuri Gerasimenko, 2014-11-18
@Mackaybravo

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; ?>

or such
<?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); ?>

Sources:
1. samsami2u.wordpress.com/2009/09/15/add-categories-...
2. www.magentocommerce.com/wiki/4_-_themes_and_templa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question