Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 3 of 3
Dispaly Subcategories Instead of Products On Category Page (With category Images) (Magento version 1.3.2.4)
 
stuarthammill
Jr. Member
 
Total Posts:  3
Joined:  2011-07-03
 
keyzo - 01 May 2011 05:33 AM

Magnaged to do it by:

if($_imageUrl=!$this->getCurrentCategory()->getImageUrl()):

foreach ($_category->getProductCollection() as $product) {

$_product = new Mage_Catalog_Model_Product();
$_product->load($product->getId());
?>
<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->backgroundColor(65,157,220)->resize(135); ?>"></a>
</div>
<div class="category-name">
<p><a href="<?php echo $this->getCategoryUrl($_category)?>">
<?php echo $catName ?></a></p>
</div>
</div>
<?php

break;
}

endif;

where do i add this bit to make it work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sannisinas
Member
 
Total Posts:  67
Joined:  2011-01-27
 

Does anybody know how to do this in magento 1.5? I see all sub cats but no images. I tried to change the navigation.php but after that I get an error on the joinurlrewrite

app\code\local\Mage\Catalog\Block\Navigation.php

(we are making a local copy so that future Magento upgrades don’t overwrite our work today.)

Then open the local version of “Navigation.php”, find:

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($productCollection);
$productCollection->addCountToCategories($categories);
return $categories;
}

And replace it with:

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($productCollection);
$productCollection->addCountToCategories($collection);
return $collection;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
therealro
Sr. Member
 
Total Posts:  102
Joined:  2010-04-09
 

Does anyone know how to show the thumbs of the sub category;s from a specific category id?

 
Magento Community Magento Community
Magento Community
Magento Community
 
xweapon
Jr. Member
 
Total Posts:  9
Joined:  2011-10-16
 

My Image will not display and I am losing my mind.... Please help!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
xweapon
Jr. Member
 
Total Posts:  9
Joined:  2011-10-16
 

This code works great to display the images but I can’t get them to display horizontally.  If I try the code for horizontal then the images do not display. I have been at this for days!!

Here is the line that displays the images correctly:

<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $_imageUrl?>” height="100"></a>

Here is the full code I am using:

<div id="categories">
<div class="col_full">
<div class="listing" >
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>
<?php foreach ($_categories as $_category):?>
<?php if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if($_imageUrl=!$this->getCurrentCategory()->getImageUrl()):?>
<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="getSkinUrl()?>images/category_image_default.gif" alt="[Image] No image available"> </a>
</div>
<div class="category-name">
<p><a href="<?php echo $this->getCategoryUrl($_category)?>">
<?php echo $catName ?></a></p>
</div>
</div>
<?php endif?>
<?php if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $_imageUrl?>” height="100"></a>
</div>
<div class="category-name">
<p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p>
</div>
</div>
<?php endif;?>
<?php endif;?>
<?php endforeach ?>
<?php /* This resets the category back to the original pages category
**** If this is not done, subsequent calls on the same page will use the last category
**** in the foreach loop
*/ ?>
<?php $layer->setCurrentCategory($_maincategorylisting);?>
<?php endif;?>
</div>
<br clear=all>
</div>
</div>

The code for horizontal I was trying to us is:

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

$_imageUrl = $_category->getImageUrl();

<a href="<?php echo $_category->getURL() ?>” title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php echo $_imageUrl?>” width="100" 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 && $i!=$_collectionSize): ?>
</tr>
<?php endif ?>
<?php endforeach ?>
<?php for($i;$i%3!=0;$i++): ?>
<td class="empty"> </td>
<?php endfor ?>
<?php if ($i%3==0): ?>
</tr>
<?php endif ?>
</table>
</div>
<br>

But the Images DO NOT SHOW UP!!!  Any help would be SOOOOO appreciated!

 
Magento Community Magento Community
Magento Community
Magento Community
 
CreativeFly
Jr. Member
 
Total Posts:  20
Joined:  2012-04-16
 

Did anybody get the images to show up on the newest versions of magneto. i’m able to display the category names horizontally but none of the images are showing up.Any help would be appreciated.Thanks in advance.

Mike

 
Magento Community Magento Community
Magento Community
Magento Community
 
P3 Pickles
Jr. Member
 
Total Posts:  9
Joined:  2011-03-21
 

Has anybody tried this on 1.7?  We would love to get this to work on our website.

 
Magento Community Magento Community
Magento Community
Magento Community
 
enass
Jr. Member
 
Total Posts:  5
Joined:  2012-07-16
 

please help me with my issue

i need the same everything as you talking and i make subcategories but i need some of products in the page and when click into any product will give me specific subcategory.

Thank you for you assitance

Enass

 
Magento Community Magento Community
Magento Community
Magento Community
 
furnituredeals
Jr. Member
 
Total Posts:  2
Joined:  2012-09-26
 

Worked for me! on 1.7
http://www.sjlwebdesign.co.uk/sjl-blog/index.php/web-design/magento-subcategories-inside-parent-category/

 
Magento Community Magento Community
Magento Community
Magento Community
 
tracikaspar
Jr. Member
 
Total Posts:  2
Joined:  2011-10-18
 

I am using Magento 1.7.0.2

I looked all over the forums for the subcategory_listing that uses the category thumbnail instead of the category image.  I found many posts but I finally put together an edited version from this post. 

Create sub-categories.phtml file
Location: app/design/frontend/YOUR-THEME/default/template/catalog/navigation/sub-categories.phtml

<div id="categories">
<div class="col_full">


<div class="listing" >
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>

<?php if($_categories->count()):?>
<? foreach ($_categories as $_category):?>

<? if($_category->getIsActive()):

$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);

$catName = $this->getCurrentCategory()->getName();

if($_imageUrl=!$this->getCurrentCategory()->getThumbnailImageUrl()):
?>

<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $this->getSkinUrl('images/subcategory-default.jpg') ?>"></a>
</div>
<div class="category-name">
<p><a href="<?php echo $this->getCategoryUrl($_category)?>">
<?php echo $catName ?></a></p>
</div>
</div>

<?endif?>

<? if($_imageUrl=$this->getCurrentCategory()->getThumbnailImageUrl()):?>
<?php /* Displays the subcategory image */ ?>

<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="media/catalog/category/<?php echo $_imageUrl?>"height="160"></a>
</div>
<div class="category-name">
<p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p>
</div>
</div>



<? 
endif;
endif;?>
<?endforeach?>

<?php /* This resets the category back to the original pages category
**** If this is not done, subsequent calls on the same page will use the last category
**** in the foreach loop
*/ ?>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
<?endif;?>


</div>
<br clear=all>
</div>
</div>

Create a static block.
Block Title: Sub Category Listing
Identifier: sub-categories
Content: {{block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"}}

Create Category.php file
You will copy this file first.
Navigate to /app/code/core/Mage/Catalog/Model/Category.php. Copy file to /app/code/local/Mage/Catalog/Model/Category.php. Once copied, edit file.

Once inside file, look near line 491. Find:

public function getImageUrl()
{
$url = false;
if ($image = $this->getImage()) {
$url = Mage::getBaseUrl(’media’).’catalog/category/’.$image;
}
return $url;
}

After this paste in:

/**
* Retrieve thumbnail image URL
*
* @return string
*/
public function getThumbnailImageUrl($fullpath = false)
{

$url = false;

if ($image = $this->getThumbnail()) {

if ($fullpath == true) {
$url = Mage::getBaseUrl(’media’).’catalog/category/’.$image;
} else {
$url = $image;
}
}

return $url;

}

Backend Magento.
Select Catalog > Manage Categories.
Create or edit the main category that will display thumbnails from sub categories.
Under Display Settings Tab
Display mode: Static block only
CMS Block: Sub Category Listing
Is Anchor: No
Thumbnail Image: Choose your file

If you do not see your edits make sure to flush your Magento cache.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tracikaspar
Jr. Member
 
Total Posts:  2
Joined:  2011-10-18
 

I also added this to my theme css - may want to change colors to match your theme:

/***** Category Sub Listing *************************************/

.category-box {
text-align: center;
float:left;
margin:05px 30px 30px 0px;
width: 200px;

}

.category-image-box {
height:200px;
width: 200x;
border: 1px solid #EEE;
}

.category-image-box img {
padding: 4px 0px 0px 0px;
}

.category-name a:link, .category-name a:visited {

font-weight: bold;
font-size: 16px;
text-decoration: none;
}

.category-name a:hover, .category-name a:active {
color: #406873;
transition: color 0.2s ease-out;
-moz-transition: color 0.2s ease-out;
-webkit-transition: color 0.2s ease-out;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrtom84
Jr. Member
 
Total Posts:  1
Joined:  2013-07-02
 

Anyone struggling to get the description to display, you need to add the following line into getCurrentChildCategories() in Navigation.php

->addAttributeToSelect(’description’)

 
Magento Community Magento Community
Magento Community
Magento Community
 
johnny703
Member
 
Total Posts:  33
Joined:  2013-02-01
 

I have multi store website..the link for images are:

<img src="media/catalog/category/55-T_4.jpg" height="160">

and it works fine if you type in:
http://newstore.worldtraveler.com/media/catalog/category/55-T_4.jpg

However, the thumbnail pictures are not loading because its putting the address as:
http://newstore.worldtraveler.com/shop-by-brands/featured-brands/media/catalog/category/55-T_4.jpg which is not found.

$url = Mage::getBaseUrl(’media’).’catalog/category/’.$image;

How do I fix this?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 3 of 3