Magento – Subcategory / Subcategories display images

We just had the problem, that for a Magento installation (Magento 1.6) thumbnails or. Gallery of the subcategories were not displayed, if you went in the main category.

By default Magento shows yes to all items, which are in the category of. But is now in the top category an image index display of all subcategories, This can with the following instructions (Thanks u.a. an Charford) be made:

1. You put a static block in the shop back in with the following parameters:

Blocktitel: Sub Category Listing
Page identifier: subcategory_listing
StoreView: Just all used where it
Status: Enabled
Content (Get off the best WYSIWYG Editor):

{{block type="catalog / navigation" template ="catalog/navigation/subcategory_listing.phtml"}}

2. Go to the appropriate category and the following settings in “Display Settings” make:

Display Mode: Only static block
CMS Block: Sub Category Listing
Is Anchor: No

3. A file named “subcategory_listing.phtmlCreate and store them in the following folder
app / design / frontend /[base or default]/[IhrTemplate]/template/catalog/navigation/
the file should contain the following code:

<?php $_categories=$this->getCurrentChildCategories(); ?>
<br>

<div class ="category-products">
<?php $_collectionSize = $_categories->count() ?>
<table class="products-grid" id="products-grid-table">
<?php $i=0; foreach ($_categories as $_category): ?>
<?php if ($i  %3==0): ?>
<tr>
<?php endif ?>
<td>
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<img src ="<?php echo $_category->getImageUrl() ?>" width="180" alt ="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
<h3 class="product-name"><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<?php echo $this->htmlEscape($_category->getName()) ?></a></h3>
</td>
<?php if ($i%3==0 && $the!=$_collectionSize): ?>
</tr>
<?php endif ?>
<?php endforeach ?>
<?php for($the;$i%3!=0;$i  ): ?>
<td class="empty">&nbsp;</td>
<?php endfor ?>
<?php if ($i%3==0): ?>
</tr>
<?php endif ?>
</table>
</div>
<br>

4. Copy the following file

appcodecoreMageCatalogBlockNavigation.php

and place it in this folder (if not available, Create)

appcodelocalMageCatalogBlock

Then open the copy in the latter folder and look for the following position (as. Line 125)

public function getCurrentChildCategories()
{
$layer = Mage::getSingleton('catalog/layer');
$category = $layer->getCurrentCategory();
/* @var $category Mage_Catalog_Model_Category */
$categories = $category->getChildrenCategories();
$productCollection = Mage::getResourceModel('catalog/product_collection');
$layer->prepareProductCollection($product collection);
$product collection->addCountToCategories($categories);
return $categories;
}

This area to replace with this code:

public function getCurrentChildCategories()
{
$layer = Mage::getSingleton('catalog/layer');
$category = $layer->getCurrentCategory();
/* @var $category Mage_Catalog_Model_Category */
$collection = Mage::getModel('catalog/category')->getCollection();
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('is_anchor')
->addAttributeToSelect('image')
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite()
->load();

$productCollection = Mage::getResourceModel('catalog/product_collection');
$layer->prepareProductCollection($product collection);
$product collection->addCountToCategories($collection);
return $collection;
}

Should it then caused a fatal error come by navigation.php, located on the “->joinUrlRewrite()” refers, then this line by

->addUrlRewriteToResult()

replace.

5. Finally, adjust the CSS file, to make everything look nice and good.

6. Something: By default, then additionally the category image displayed again in the respective category. Should not be the case, in the view.phtml in the folder /app / design / frontend /[base or default]/[IhrTemplate]/template/catalog/category as. in line 52 the range

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

Delete or comment out.

Now what is required for the display of images of course category, that these are also stored in the categories. These can be uploaded directly in the backend in the category.
Should the size of the images are adjusted, or in the subcategory_listing.phtml set the desired size. adapt.

If it still does not work now, in doubt under “Own design” Select the category has the required template.

Used in Magento Version 1.6.2.0. Comments, Suggestions, Ask? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

11 comments on “Magento – Subcategory / Subcategories display images”

  1. Hallo,

    Easy to follow instructions thank you but to me it always shows:

    Fatal error: Call to a member function getCurrentCategory() on a non-object in /home/.sites/137/site890/web/shop/app/code/local/Mage/Catalog/Block/Navigation.php on line 128

    where the fault lies?

    mfg
    Christian

    1. Ja, danke für die Anleitung. Ich habe aber das selbe Problem wie mein “Vorredner”. Die selbe Fehlermeldung. Gibt es da eine Lösung?
      Tibor

  2. Hi,
    hatte das gleiche Problem, checkt mal die einfachen Tüddelchen im Code, ich musste diese neu setzen, zB aus
    $layer = Mage::getSingleton(&#8216;catalog/layer&#8217;);
    was
    $layer = Mage::getSingleton(&#8216;catalog/layer&#8217;);

    usw.. das gleiche im Schritt 1 at
    {{block type=”catalog/navigation” template=”catalog/navigation/subcategory_listing.phtml”}}

    evtl liegts an der Schriftart hier im Blog, auch die doppelten Anführungszeichen musste ich neu setzen.

    1. Thanks for the tip, ich muss mich Stück für Stück durch die alten Beiträge arbeiten und den Code in entsprechende Klammern setzen, die ich damals noch nicht hatte. Nun habe ich es bei diesem Artikel aber auch mal gemacht.

  3. Hallo,
    Alles geklappt! Thanks for the instructions. You also get the description of the subcategory to each image purely? CategoryName goes also..

  4. Hallo,

    Super Guide! THANK YOU!!!

    How can you change the following:
    – Center text under the picture
    – Determine images / categories per row
    – Set distance between the images

  5. Leider werden bei mir nur die für die Hauptkategorie hinterlegten Bilder angezeigt, sprich ich klicke auf die Hauptkategorie und bekomme dann das Bild der Hauptkategorie angezeigt und nicht etwa die der weiteren Unterkategorien.
    Woran könnte das liegen?

Leave a Reply

Your email address will not be published. Required fields are marked *