Some time you may be need to show subcategories of category on landing page
Navigate to the following page and change the page code with the following code:
app/design/frontend/rwd/default/template/catalog/category/view.phtml
<?php /** * Category view template * * @see Mage_Catalog_Block_Category_View */ ?> <?php $_helper = $this->helper('catalog/output'); $_category = $this->getCurrentCategory(); $_imgHtml = ''; if ($_imgUrl = $_category->getImageUrl()) { $_imgHtml = ' <img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /> '; $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image'); } ?> <div class="page-title category-title"> <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?> <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a> <?php endif; ?> <h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h1> </div> <?php echo $this->getMessagesBlock()->toHtml() ?> <?php $level= $this->getCurrentCategory()->getLevel(); ?> <?php if($_imgUrl && $level==2): ?> <?php echo $_imgHtml ?> <?php endif; ?> <?php if($level==2): ?> <?php $obj= new Mage_Catalog_Block_Navigation(); $_helper = Mage::helper('catalog/category'); $current_cat = $obj->getCurrentCategory(); $currentCatId = (is_object($current_cat) ? $current_cat->getId() : ''); $currentPage = (int) $this->getRequest()->getParam('p', 1); $pageSize = 3; $collection = Mage::getModel('catalog/category')->getCollection() ->addAttributeToFilter('parent_id', $currentCatId) ->addFieldToFilter('is_active', 1) ->addAttributeToSelect('name') ->addAttributeToSelect('url') ->setLoadProductCount(1) ->setOrder('name', 'asc') ->setPage($currentPage, $pageSize); $totCat = $collection->getSize(); $store_cats = $collection->load(); $pageTot = ceil( $totCat / $pageSize ); $variable = $_GET["p"]; if($variable ==''){ $variable = 1; } $prev = $variable-1; $next = $variable+1; ?> <ul class="products-grid products-grid--max-2-col"> <?php foreach ($store_cats as $_subcategory): ?> <?php $_subcategory = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?> <?php if (count($_subcategory) > 0): ?> <?php// echo count($_subcategory)?> <li class="item"> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>" class="product-image"> <?php $subcategory = Mage::getModel('catalog/category')->load($_subcategory->getId()); $img_url = $subcategory->getImageUrl() ?> <img src="<?php echo $img_url; ?>" /> </a> <div class="product-info"> <h2 class="product-name"> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <?php echo $_subcategory->getName() ?> </a> </h2> </div> </li> <?php endif; ?> <?php endforeach; ?> </ul> <?php echo $this->getPagerHtml() ?> <div class="toolbar-bottom"> <div class="toolbar"> <div class="pager"> <div class="pages"> <ol> <?php if($variable>1):?> <li class="left"><a href="<?php echo $current_cat->getUrl() ?>?p=<?php echo $prev; ?>">left</a></li> <?php endif; ?> <?php for ( $i=1; $i<=$pageTot; $i++ ) : ?> <?php if ( $i == $currentPage ) : ?> <li class="active"><?php echo $i ?></li> <li><span><?php echo $this->__('of')?></span></li> <li><span><?php echo $pageTot ?></span></li> <?php endif; ?> <?php endfor; ?> <?php if($variable < $pageTot):?> <li class="right"><a href="<?php echo $current_cat->getUrl() ?>?p=<?php echo $next; ?>">right</a></li> <?php else: ?> <li></li> <?php endif; ?> </ol> </div> </div> </div> </div> <?php else: ?> <?php if($_description=$this->getCurrentCategory()->getDescription()): ?> <div class="category-description std"> <?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?> </div> <?php endif; ?> <?php if($this->isContentMode()): ?> <?php echo $this->getCmsBlockHtml() ?> <?php elseif($this->isMixedMode()): ?> <?php echo $this->getCmsBlockHtml() ?> <?php echo $this->getProductListHtml() ?> <?php else: ?> <?php echo $this->getProductListHtml() ?> <?php endif; ?> <?php endif; ?>
0 Comments