magento show categories on left sidebar on a page

与世无争的帅哥 提交于 2019-12-12 08:14:33

问题


I cant manage to show on a page, on the left side the categories. I selected for the page under Design - layout to 3 columns, Right side shows fine but nothing on left side. New to magento so i`m not sure in wich file in the template i have to look for. Its a custom template installed so i got so far to:

app/design/frontend/default/f001/template/

but not sure now if to look under catalog or paeg folders


回答1:


Go to layout Xml folder..

Blockquote /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>

further 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"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
        foreach ($obj->getCurrentChildCategories() as $subcat) {
            echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
        }
        echo "</ul>\n</li>\n";
    } else {
        echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
    }
}
?>



回答2:


Go to Layout folder i.e.

app/design/frontend/default/f001/layout/

open any xml file e.g. catalog.xml and under tags

<default>

</default>

paste in this code

<reference name="left">
        <block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
    </reference>

like this

<default>
    <reference name="left">
        <block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
    </reference>
</default>

But make sure to comment this block on line number 79.

<!-- <reference name="left">
    <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->



回答3:


To move the categories from the right sidebar to the left sidebar you'll need to do this:

(1) Open app/design/frontend/default/f001/layout/ and find a file called local.xml - If it does not exist, create it.

Paste the following inside and save.

<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<!-- Left Categories Begin-->
   <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" before="-" template="catalog/navigation/left.phtml"/>
    </reference>
<!-- Left Categories End-->
</default>
</layout>

(2) Open app/design/frontend/default/f001/layout/catalog.xml

Inside "Category default layout", look for something like this and comment this line out (like so)-

<!-- <reference name="right">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference> -->

That will prevent the categories from displaying on both sidebars, assuming you're using a 3 column.

The reference name, as you might have guessed, refers to each sidebar. You'll need to make sure that the reference name for "left" contains the left categories, and make sure the right does not (controlled in layout, not template files).




回答4:


Add this in left static block
<p>Left side bar {{block type="core/template" template="catalog/navigation/left.phtml"}}</p>

add left.phtml in yourtemplatename/template/catalog/navigation/left.phtml
<?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"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
        foreach ($obj->getCurrentChildCategories() as $subcat) {
            echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
        }
        echo "</ul>\n</li>\n";
    } else {
        echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
    }
}
?>


来源:https://stackoverflow.com/questions/8392688/magento-show-categories-on-left-sidebar-on-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!