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

Category page to list sub-categories
 
RichardWork
Jr. Member
 
Total Posts:  11
Joined:  2008-04-17
 

I am working on a site design that is organised as:

Category1
- Sub-category 1a
- Sub-category 1b
- Product 1b.1
- Product 1b.2
Category2
...

Is it possible to configure the pages for the top level category pages (Category1 and Category2), so they list the sub-categories and display an icon for each page similar to the grid layout of products, and to do it dynamically rather than using a static block.

Thanks in advance

Richard

 
Magento Community Magento Community
Magento Community
Magento Community
 
RichardWork
Jr. Member
 
Total Posts:  11
Joined:  2008-04-17
 

From a post by Moshe

How to Add Specific Content to Home Page (from a phtml file)?

I am now looking at using a modified version of the navigation/left.phtml code but called within the content area of the one or two columns template. I have then added the following to Categories/Custom Design tab, Custom Layout Update:

<reference name="root">
<
block type="catalog/category_list" name="catalog.category.list" as="categorylist" template="catalog/category/list.phtml"/>
</
reference>

Can this be called from the 2columns-right.phtml template in this way, or how can it be called to list the sub-categories below the current page when there are no products on this page?

 
Magento Community Magento Community
Magento Community
Magento Community
 
RichardWork
Jr. Member
 
Total Posts:  11
Joined:  2008-04-17
 

Success, I copied the .phtml file (catalog/navigation/left.phtml) used to create the “Shop By” category list in the left column to ./app/design/frontend/<implementation>/default/templates/catalog/category/, and called it list.phtml.

Then created a new Static Block with the content:

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}

the type needs to be catalog/navigation. Now to see if I can get it to display an image for each of the sub categories.

 
Magento Community Magento Community
Magento Community
Magento Community
 
corbykissler
Member
 
Total Posts:  39
Joined:  2008-05-14
 

i had to do the same thing -

Here’s the code I used to do it - contains the images being displayed.

<?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);  
           if(
$_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
            
                        
<div><div class="linkimage"><p>
<
a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $_imageUrl?>"></a></p></div><p><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></p></div>
<?                                              
                 
                 
                 
else: ?>
                 
                 
<div><p><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></p></div>


<?
                 
                 
                 
                        
endif;
 
Magento Community Magento Community
Magento Community
Magento Community
 
batkins
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-05-10
 

I’m trying to create a static block on a category page that will show the images and link to the corresponding sub-categories. I saw your post and code, but can’t get it to work. Any ideas or suggestions?

here is what I’ve done:
1. static block title:category id:category / activated in category including:

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}

2. Custom design - 2 columns with right bar - custom layout:

<reference name="root">
<
block type="catalog/category_list" name="catalog.category.list" as="categorylist" template="catalog/category/list.phtml"/>
</
reference>

3. created list.phtml including this code:

<?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);  
           if(
$_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>

<div><div class="linkimage"><p>
<
a href="<?php echo $this->getCategoryUrl($_category)?>"><img src="<?php echo $_imageUrl?>"></a></p></div><p><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></p></div>
<? else: ?><div><p><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></p></div>
<? endif; ?>
Might you have any suggestions?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
a0z0ra
Jr. Member
 
Total Posts:  8
Joined:  2008-05-14
 

Since you’re using catalog/navigation block type, it doesn’t have image attribute on its categories.  Modify /app/code/core/Mage/Catalog/Block/Navigation.php line 74 by adding ->addAttributeToSelect(’image’)

See below

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('image')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
joinUrlRewrite()
            ->
load();

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

Mine is Magento ver. 1.0.19870.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
Scabro
Jr. Member
 
Total Posts:  16
Joined:  2008-11-28
 

Hi guys,

I’ve done what’s described here but for some reason I’m getting the following error:

“<b>Parse error</b>:  syntax error, unexpected $end in <b>/home/mediades/public_html/ecommerce/magento/app/design/frontend/default/default/template/catalog/category/list.phtml</b> on line <b>22</b>”

Any idea?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Scabro
Jr. Member
 
Total Posts:  16
Joined:  2008-11-28
 

I’ve found the answer here: http://www.magentocommerce.com/boards/viewthread/14527/P15/

which gives the right code for the list.phtml page:

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

<div class="listing-type-list catalog-listing">
    
<?php foreach ($_categories as $_category): ?>
    
<table width="100%" border="0" cellspacing="0" cellpadding="0">
            
<?php if($_category->getIsActive()): ?>
            
<tr>
                <
td width="30%">
                    <
div class="listing-item">
                        <
div class="cat-box-text">
                        <
h6><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h6>
                        </
div>
                        <
div class="product-image">
                            <
a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
                                <
img src="<?php echo $_category->getImageUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
                            </
a>
                                
<?php /* echo "Find this item->" */ ?>
                        
</div>
                    </
div>
                
                </
td>
                <
td width="40%">
                    <
div class="listing-item">
                        <
div class="cat-box-text">
                        
<?php echo $_category->getDescription() ?>
                        
</div>
                    </
div>
                </
td>
            
<?php endif; ?>
            
</tr>
        </
table>
    
<?php endforeach; ?>
</div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
VortexCommerce
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-08-06
Harrogate, UK
 

Hi,

I have had a good look through the forum for code to display a category list like on http://www.ebuyer.com. So far I haven’t had much luck, anyone in here any any thoughts.

The page I want to have this displaying is here http://www.zillu.co.uk/inspired/

Thanks,
Bruce

 
Magento Community Magento Community
Magento Community
Magento Community
 
jackied
Member
 
Total Posts:  31
Joined:  2008-07-02
 

I added the content to the list.phtml from Scabro. It looks great other than the fact that it doesn’t pull the images and description. Any clue why that might be happening?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jackied
Member
 
Total Posts:  31
Joined:  2008-07-02
 

Nevermind… see comment from a0z0ra above.

 
Magento Community Magento Community
Magento Community
Magento Community
 
moomarketing
Jr. Member
 
Total Posts:  10
Joined:  2009-04-03
 
jackie.d - 22 April 2009 12:26 PM

I added the content to the list.phtml from Scabro. It looks great other than the fact that it doesn’t pull the images and description. Any clue why that might be happening?

Thanks!

Hey Jackie, I have been going mental with this problem, I got the issue sorted using the following thread:

http://www.magentocommerce.com/boards/viewthread/3770/P30/

 
Magento Community Magento Community
Magento Community
Magento Community
 
bren1818
Jr. Member
 
Total Posts:  4
Joined:  2011-06-07
 

Thanks for the helpful posts. I cleaned it up a little and went with something like this:

<?php 
$_category 
$this->getCurrentCategory(); 
$collection Mage::getModel('catalog/category')->getCategories($_category->entity_id);

$rootcat $_category->entity_id
$cat Mage::getModel('catalog/category')->load($rootcat); 
$child $cat->getChildren(); 
//echo $child;

if($child

    $helper 
Mage::helper('catalog/category'); 
    
$_helper $this->helper('catalog/output'); 
    
?> 
    
<div class="category-custom-products"
    <
table>
        <
tr>
            <
td valign="top" width="405">
                <
h1 class="page-title"><?php echo $_helper->categoryAttribute($_category$_category->getName(), 'name'?></h1>
                
<?php
                    $_imgUrl 
$_category->getImageUrl();
                    echo 
'<img id="ProductCategoryImage" src="'.$_imgUrl.'"/>';
                
?>

            
</td>
            <
td width="40">
            
            </
td>
            <
td valign="top">
                <
div class="products-grid categories-grid">

                
<?foreach ($collection as $cat):?> 
                    <?php 
if($_category->getIsActive()):?> 
                        <?php 
                            $cur_category 
Mage::getModel('catalog/category')->load($cat->getId()); 
                            
$_imgUrl $cur_category->getImageUrl();
                        
?>
                        
<div class="categoryItem"
                            <
class="categoryImageLink" href="<?php echo $helper->getCategoryUrl($cat);?>"><?php echo '<img class="categoryImg" width="216" height="180" id="ProductCategoryImage" src="'.$_imgUrl.'"/>'?></a>    
                            <
class="categoryProductLink" href="<?php echo $helper->getCategoryUrl($cat);?>"><?php echo $cat->getName();?></a
                            <
class="viewDetailsLink" href="<?php echo $helper->getCategoryUrl($cat);?>">view details</a
                        </
div

                    
<?php endif?> 
                <?php 
endforeach;?> 
                
</div>
                </
td>
                </
tr>
                </
table>
            </
div
    
<?php 

else 

?> 
    <?php 
echo $this->getProductListHtml() ?> 
<?php 

?>

Then I styled it so I have the Main Category image on the left, and then then the list of it’s sub categories on the right.

Hope this helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Darpanweb
Jr. Member
 
Total Posts:  7
Joined:  2009-05-07
 

Hi there

I bought layered navigation extension, I have a big problem to show category level.
what I want.
When I click on Designers : left side show only designers list
When I click on Designers : left side show 2 level category, example: bags >> shoulder bags
When I click on bags or shoulder bag : still showing above category,.

currently when i click on shoulder bags, left side no more category display only price and size filter show.

any one help me for this

very urgent

thank you in advance

 
Magento Community Magento Community
Magento Community
Magento Community
 
retched
Jr. Member
 
Total Posts:  18
Joined:  2011-11-05
 

So I went ahead and I completed making these changes and it works fine. However, there is one small problem.

I need to know if there’s a way to display a default “no image” category icon. Yes I know its silly but it helps. I tried to use the code for the default “no image” of the products, but that’s not leading me anywhere.

Any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top