custom layout for all categories page magento - magento

I want to display subcategory images on category page over products.
1. I have created category_listing.phtml with custom code to show subcategories
2. Created a static block
{{block type="core/template" template="catalog/navigation/category_listing.phtml"}}
On category display setting I have selected 'static block and products'.
say i have three categories
category 1
category 2
category 3
if i select static block for one category only perfect but if i call static block in more than one category it shows wrong subcategories unless i delete cache everytime.
Is there any step i am missing, plz reply considering i am new to magento
Thanks

1. For Custom category menu navigation in Magento
The layout
Open app/design/frontend/base/default/layout/page.xml or your theme’s equivalent.
Place the following code under default tag:
<reference name="right">
<block type="core/template" name="catalog.sidenav" template="page/custom.phtml" before="cart_sidebar"/>
</reference>
Create app/design/frontend/base/default/template/page/custom.phtml with the following content:
<ul>
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li>
<strong><?php echo $_category->getName(); ?></strong>
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
You can also insert this template to any other page by coding a layout update or via admin, by inserting this line as content of your CMS page:
{{block type="core/template" template="page/custom.phtml"}}
2.To add category navigation in left sidebar:
create new file "category_listing.phtml" in your theme at -
app/design/frontend/{your_namespace}/{your_module}/template/catalog/navigation/category_listing.phtml
Put the following code in it:
<div class="block block-category">
<div class="inside-box">
<div class="block-title block-category-title">
<h2><?php echo $this->__('Categories') ?></h2>
</div>
<div class="block-category-navigation">
<ul id="category-nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->name!=""): ?>
<li><?php echo $this->drawItem($_category) ?></li>
<?php endif?>
<?php endforeach ?>
</ul>
</div>
</div>
</div>
then call this in the catalog.xml file located in the theme folder -
app/design/frontend/{your_namespace}/{your_module}/layout/catalog.xml
code:
<reference name="left">
<-- this is new block added by us -->
<block type="catalog/navigation" name="catalog.categorymenu" after="top.search" template="catalog/navigation/category_listing.phtml"/>
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
...
...
...
</reference>

Open File :app/design/frontend/yourtheme/default/template/catalog/category/view.phtml
And add the the below code :
<div class="category-grid-new">
<?php $_columnCount = 4;?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="sub-category">
<?php endif; ?>
<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0):?> last<?php endif; ?>">
<a href="<?php echo $_subcat->getUrl() ?>">
<div class="category-img"><img src="<?php echo $_category->getImageUrl() ?>" alt="" width="100px" height="100px"/></div>
<div class="category-name"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName()) ?></div>
</a>
</li>
<?php endforeach; ?>
<?php if ($i%$_columnCount==0): ?>
</ul>
<?php endif; ?>
</div>

Related

Magento pagination is not displaying on Catalog page

In my magento website it is not displying page numbers on the bottom....In this website I have around 6-7 categories and every category has around 50 products
Changes I have made to the Magento admin panels are:
under admin -> Catalog -> Catalog -> Frontend
And under admin -> General -> Design-> Pagination
I'hv only made changes in these
Still page number on the product page not showing on here
Any Ideas why its happening?
EDIT:
This is my frontend\mgstheme\luxury\template\catalog/category/view.phtml page
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img class="img-responsive" src="' . $_imgUrl . '" alt="' . $this->escapeHtml($_category->getName()) . '" title="' . $this->escapeHtml($_category->getName()) . '" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
$settingDescPosition = 1;
$setting = Mage::getModel('mpanel/setting')->load($_category->getId());
if($setting){
if($setting->getRatio()!=''){
$settingDescPosition = $setting->getDescPosition();
}
}
?>
<div class="page-title category-title">
<?php if ($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
<?php echo $this->__('Subscribe to RSS Feed') ?>
<?php endif; ?>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $helper = $this->helper('mpanel'); ?>
<div class="custom">
<div class="container">
<span><i class="fa fa-home"></i> / <span>Products</span> / <span><strong><?php echo $this->getCurrentCategory()->getName(); ?></strong></span></span>
</div>
</div>
<?php if ($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif ($this->isMixedMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<div id="product-list-container">
<?php echo $this->getProductListHtml() ?>
</div>
<?php else: ?>
<div id="product-list-container">
<?php echo $this->getProductListHtml() ?>
</div>
<?php endif; ?>
<?php if ($helper->acceptToUsePanel()): ?>
<?php // description position below product list ?>
<?php if($settingDescPosition==2): ?>
<div class="builder-container inline-builder">
<?php if ($_description = $this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php echo $helper->getEditCategoryDescription($_category->getId()) ?>
<?php else: ?>
<div class="category-description std">
<span class="placeholder">Add description for this category</span>
</div>
<?php echo $helper->getEditCategoryDescription($_category->getId()) ?>
<?php endif; ?>
</div>
<?php endif ?>
<?php else: ?>
<?php // description position below product list ?>
<?php if($settingDescPosition==2): ?>
<?php if ($_description = $this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php endif; ?>
<?php endif ?>
<?php endif; ?>
Solved
Added this code to the view.phtml
<?php echo $this->getToolbarBlock()->setTemplate('catalog/product/list/bottom_toolbar.phtml')->toHtml(); ?>
Check in the catalog.xml whether you have called xml for pagination. The xml should be as below
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
As per your screenshot, you are using custom theme so please recheck all phtml files are in there folder related with pagination.
If still you are facing the same issue, so please see the below link that will help you :
https://support.webcto.eu/index.php/Knowledgebase/Article/View/43/8/paginating-not-shown-in-magento

Show categories on left and not on top navigation

I tried implemented a code in my Navigation/left.phtml
The code is as follows
<!-- subcategory code -->
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
if(!$category->getChildren()){
//$parentcat_id = $category->getParentCategory()->getId();
//$category = Mage::getSingleton('catalog/category')->load($parentcat_id);
$category = $category->getParentCategory();
}
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren());
?>
<div class="block">
<div class="block-title">
<span><?php echo $category->getName() ?></span>
</div>
<div class="block-content clearfix">
<ul class="subcategories">
<?php foreach ($categories as $category): ?>
<li>
<a href="<?php echo $category->getUrl() ?>"><!--<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />-->
<span><?php echo $category->getName() ?>
<?php $collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($category);
echo "(".count($collection).")"; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul></div>
</div>
<!-- subcategory code -->
<!-- List all categories and their second level subcategories -->
<div class="block block-list block-categories">
<div id="block-categories" class="block-title active">
<strong><span>Categories </span></strong>
</div>
<div id="leftnav" class="block-content" style="display:block">
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php if (count($categories) > 0): ?>
<ul id="leftnav-tree" class="level0">
<?php foreach($categories as $category): ?>
<li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
<?php //if ($this->isCategoryActive($category)): ?>
<?php $subcategories = $category->getChildren() ?>
<?php if (count($subcategories) > 0): ?>
<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
<?php foreach($subcategories as $subcategory): ?>
<li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?>
<?php $secondLevelSubcategories = $subcategory->getChildren() ?>
<?php if (count($secondLevelSubcategories ) > 0): ?>
<ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2">
<?php foreach($secondLevelSubcategories as $secondLevelSubcategory ): ?>
<li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory )): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
<?php endif; ?>
<?php //endif; ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
<?php endif; ?>
</div>
</div>
But when i set Include in Navigation Menu to No it also disappears from here.
Is there any way I can hide from top menu and show in my side menu?
Demo link is http://infigic.com/ds4u/
If you don't have local.xml file just create one in the layout folder of your theme and populate it with this content:
<?xml version="1.0"?>
<layout>
<default>
<reference name="header">
<action method="unsetChild"><name>top.menu</name></action>
</reference>
<reference name="left">
<action method="insert"><child>top.menu</child></action>
</reference>
</default>
</layout>
Changing your collection request to this should work :
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1) // there is the 'magic'
->addIdFilter($category->getChildren());
Although, I do not recommend you to do it like this.
Because:
You are breaking the MVC pattern of Magento when requesting a model from a view
You are doing over complicated things that you may probably achieve easier by doing a block which extends Mage_Catalog_Block_Navigation, where the category may already be filtered the right way, but not rendered as you would like.
Please have a look at base Magento template (well not only the one in /app/design/frontend/base, but the one coming with a fresh install of Magento) and you'll see that never ever are there going to be a direct call in a view to a model instance.
For Magento good practice, please refer to the perfect blog of Alan Storm (who also is a SO member) here and maybe more specifically to this chart showing how templates (view) should interact with blocks to render models.

How to display all categories in magento project

am new to magento 1.7 and am using celebrity theme now what i want is to add all the categories to be displayed in left side bar , i have browsed through n tried many but none of them are working (May be due to Celebrity theme). So can any one help me on this ASAP. PLEASE
you can add like this
go to your layout.xml and add like this
/app/design/frontend/default/default/layout/catalog.xml
Open this Xml file and paste this code.
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>
open this file ..
/app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml
paste this code:
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current">'.$cat->getName()."\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li>'.$cat->getName()."</li>\n";
}
}
?>
EDIT
LIST ALL CATEGORIES
$_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php //if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
<?php $_category1 = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
<?php $_subcategories1 = $_category1->getChildrenCategories() ?>
<?php if (count($_subcategories1) > 0): ?>
<ul>
<?php foreach($_subcategories1 as $_subcategory1): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory1) ?>">
<?php echo $_subcategory1->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php // endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif;?>

I want to display the category and its child category structure on my page like below in magento 1.7

I'm new in magento and having problem with the category and its child category and their products structure .
plz can anyone give me the code to implement exactly the same structure .
I want structure like this on the content area ,not in the any side bar or header navigation :-
Main Category Name
Subcategory1 Name
Product 1
Product 2
.
.
Subcategory2 Name
Product 1
Product 2
.
.
and this should be work for every category.
Can anyone solve this ?
Thanks in advance :)
Here is some code I have used to display sub category tiles on a category page.
https://www.evernote.com/shard/s4/sh/cc805407-a0d5-4d74-8cd2-b2d7513262f1/9934b5a9f09962b90fe5ecf76f06deb5
I would suggests not to ask the for code better you try this people here can give idea.
Then also...
Go to following path in your magento(Note: Here I am using base/default/default you have to use in your template file).
/app/design/frontend/base/default/template/catalog/navigation
Create New file vert-navigation.phtml
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<div class="vertical-nav">
<div class="navi-title"><h2>BROWSE BY CATEGORY</h2></div>
<?php echo $this->getChildHtml('topSearch') ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php //if ($currentCategory->getName() == $_category->getName()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories();
//$count=0; ?>
<?php if (count($_subcategories) > 0): ?>
<!--li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a-->
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php //$count++; ?>
<?php //if($count==4) break; ?>
<?php endforeach; ?>
</ul>
<?php //endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Then go to /app/design/frontend/base/default/layout/catalog.xml place the below code
<reference name="content">
<!--block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/-->
<block type="catalog/navigation" before="-" name="catalog.vertnav" template="catalog/navigation/vert-navigation.phtml"/>
</reference>
You will see the full listing of Category do style as you requirement.

Set breadcrumb for one of the pages of Magento?

I have this page for instance that doesn't have a proper breadcrumb set: http://www.princessly.com/checkout/cart/
It's just "Home >>" and that's it.
How can I make it "Home >> Shopping Cart"?
Thus far I can only find the breadcrumb template which is template/page/html/breadcrumbs.phtml but I have no idea how to make this change.
I suppose I should add a line in the shopping cart page template?
Try adding the following code to local.xml of your theme:
<checkout_cart_index>
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/home</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>Shopping Cart</crumbName>
<crumbInfo><label>Shopping Cart</label><title>Shopping Cart</title><link>/checkout/cart</link></crumbInfo>
</action>
</reference>
</checkout_cart_index>
For some reason sometimes we need to touch the template on code>page>html>breadcrumbs.phtml. Just remember to move before to your template.
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->__($this->htmlEscape($_crumbInfo['label'])) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->__($this->htmlEscape($_crumbInfo['label'])) ?></strong>
<?php else: ?>
<?php echo $this->__($this->htmlEscape($_crumbInfo['label'])) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>/ </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
The translate is performed by
$this->__("someText");

Resources