0

I want to add some of my categories on homepage, not all but three or four of them by category id. I read something that I have to create a list.phtml and add this as follows to my homepage cms content:

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

But I am using a custom theme and in this theme exists a mdl-banner.phtml file (path: customtheme/template/catalog/product) which displays a slider on homepage. This file looks as follows:

<?php 
    $config = Mage::getStoreConfig( 'bannerslider/homepage' );
?>
<div class="container">
    <div class="submenu span3">
        <!-- categories -->
    </div>
    <div class="slide span9 f-fix">
        <div class="container">
            <?php echo $this->getLayout()->createBlock('bannerslider/default')->setTemplate('mdl/bannerslider/bannerslider.phtml')->setBannersliderId(1)->toHtml(); ?>
        </div>
    </div>
</div>

Now I just want to add some categories there where the comment is.

So I changed this file as follows:

<?php 
    $config = Mage::getStoreConfig( 'bannerslider/homepage' );
?>
<div class="container">
    <div class="submenu span3">
        <?php $specialCategoryIds = array( '5', '6', '7' ); ?>
        <?php foreach ( $this->getStoreCategories() as $category ): ?>
            <?php $categoryId = $category->getId(); ?>
            <?php if ( !in_array( $categoryId, $specialCategoryIds ) ) continue; ?>
                <?php $open = $this->isCategoryActive( $category ); ?>
                <?php if ( $open ): ?>
                    <a href="<?php echo $this->getCategoryUrl( $category )?>">
                        <?php echo $category->getName(); ?>
                    </a>
                <?php endif; ?>
            <?php endif; ?>
        <?php endforeach; ?>
    </div>
    <div class="slide span9 f-fix">
        <div class="container">
            <?php echo $this->getLayout()->createBlock('bannerslider/default')->setTemplate('mdl/bannerslider/bannerslider.phtml')->setBannersliderId(1)->toHtml(); ?>
        </div>
    </div>
</div>

But now I am getting a blank screen on homepage, because I think I have to say magento that categories are enabled for my homepage, but I don't know where I have to do this because I didn't used a list.phtml? Hope you understand my problem and can help me :)

EDIT:

I changed this file again to:

<?php 
    $config = Mage::getStoreConfig( 'bannerslider/homepage' );
?>
<div class="container">
    <div class="submenu span3">
        <?php echo $this->getLayout()->createBlock('catalog/navigation')->setTemplate('catalog/category/list.phtml')->toHtml(); ?>
    </div>
    <div class="slide span9 f-fix">
        <div class="container">
            <?php echo $this->getLayout()->createBlock('bannerslider/default')->setTemplate('mdl/bannerslider/bannerslider.phtml')->setBannersliderId(1)->toHtml(); ?>
        </div>
    </div>
</div>

and its working now for me, but is this a good solution?

0

A better solution would be, to create a custom widget, where you can select the corresponding categories you want to show and just use this widget at the cms page or template

  • Ok thank you, but I am just a magento beginner. If I want to create a custom widget then I have to proceed like building an extension? – Fox Feb 13 '15 at 13:47
  • Thats right, but there are pretty good tutorials out there, even from magento like: Widget Tutorial Part 1 – Peter Liebig Feb 13 '15 at 13:48
  • Ok thanks again, I have some much to learn :) – Fox Feb 13 '15 at 13:51
  • No problem, everyone needs to start :) – Peter Liebig Feb 13 '15 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.