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

How do I list subcategories on the main content sections? 
 
Steven Masterson
Jr. Member
 
Total Posts:  1
Joined:  2009-08-24
 

Hello,

I’m designing a website that will have several main categories and will have several hundreds of 1-level subcategories, so I’m trying to make a CMS page that will display all the child categories of the current parent.

Here’s what I’ve tried so far

I’ve added this in Custom Layout update section of the parent category:

<reference name="content">
    <
block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/categorypage.phtml"/>
</
reference>

and I created a categorypage.phtml under template/catalog/navigation, its content is as follow:

?php if (!Mage::registry('current_category')) return ?>
<?php $_categories
=$this->getCurrentChildCategories() ?>
<?php $_count 
is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php 
if($_count): ?>
        
<h3><?php echo $this->__('Browse By'?></h3>
            <
dl>
                <
dt><?php echo $this->__('Category'?></dt>
                <
dd>
                    <
ol>
                    
<?php foreach ($_categories as $_category): ?>
                        <?php 
if($_category->getIsActive()): ?>
                        
<li>
                            <
a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?></a>
                        </
li>
                        
<?php endif; ?>
                    <?php 
endforeach ?>
                    
</ol>
                </
dd>
            </
dl>
<?php endif; ?>

I basically took those codes out from the original navigation/left.phtml, I just removed all the styling from it so it will just display a plain ordered list for testing purpose. This method, kind of worked, because I did get a clean, unstyled ordered list, but at the same time my real navigation on the left of the page also turned into the same unstyled ordered list, the worst part, both of their content is exactly the same.

I think my problem right now is I don’t know what blocktype to use for this new phtml, I’m assuming that I can’t have two blocks of the same type appear on the same page but points to a different phtml file.

here is the website I’m working on, the problem can be seem if you click on Electronis category on the left
http://www.maximumtoners.com

by the way, the navigation you see on the left is actually not the original magento navigation, I moved the content from top menu to there by replacing everything in left.phtml with this:

<div class="box layered-nav">
    <
div class="head">
        <
h3><?php echo 'Shop By' ?></h3>
    </
div>
    <
div class="border-creator">
        <
div class="narrow-by">
            <
dl id="narrow-by-list">
                <!--<
dt><?php echo $this->__('Category'?></dt>-->
                <
dd>
                    <
ol>
                    
<?php foreach ($this->getStoreCategories() as $_category): ?>
                        
<li>
                            <
a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?></a>
                        </
li>
                    
<?php endforeach ?>
                    
</ol>
                </
dd>
            </
dl><script type="text/javascript">decorateDataList('narrow-by-list')</script>
        
</div>
    </
div>
</
div>

Thanks for your help, I really appreciate it.

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