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

Page 1 of 2
left.phtml menu on home page
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Solved: http://www.magentocommerce.com/boards/viewthread/20632/#t69887

Greetings,

First look at Magento here so still working on finding my way around and understanding the database structure and framework. However, this should be pretty straight forward. I was hoping to copy the left.phtml file, rename it left_home.phtml and call it from the Layout Update XML in the Custom Design feature of the CMS > Manage Pages > Home page. Then copy, adjust and rename the getCurrentChildCategories() function in the Navigation.php file to getMainCategories() and updating the reference to it in the left_home.phtml.

Calling the function as is on the home page will throw an error at $layer->getCurrentCategory(). I’m having some issue with setting the current category to be the root category and would appreciate any help anyone has to offer.

Kind regards,

LL

/**
     * Retrieve child categories of current category
     *
     * @return Varien_Data_Tree_Node_Collection
     */
    public function getCurrentChildCategories()
    
{
        $layer 
Mage::getSingleton('catalog/layer');
        
$category   $layer->getCurrentCategory();
        
/* @var $category Mage_Catalog_Model_Category */
        
$collection Mage::getModel('catalog/category')->getCollection();
        
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
setOrder('position''ASC')
            ->
joinUrlRewrite()
            ->
load();

        
$productCollection Mage::getResourceModel('catalog/product_collection');
        
$layer->prepareProductCollection($productCollection);
        
$productCollection->addCountToCategories($collection);
        return 
$collection;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Hi guys, sorry to bump this thread but I’ve searched the forums extensively and was unable to find information on how to get the left.phtml menu to display on the home page. Some help with this would be most appreciated. smile

Kind regards,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Alright, now that I’ve had more time look at the Magento database structure, here’s the updated query and code to display the left.phtml menu on the home page.

This example uses Magento v1.1.6

1. Copy/Paste the following code into line 67 of Navigation.php:
(app/code/core/Mage/Catalog/Block/Navigation.php)

/**
     * Retrieve child categories of root category
     *
     * @return Varien_Data_Tree_Node_Collection
     */
    public function getMainCategories()
    
{
        $collection 
$this->getData('category_collection');
        if (
is_null($collection)) {
            $collection 
Mage::getModel('catalog/category')->getCollection();

            
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
            
$collection->addAttributeToSelect('url_key')
                ->
addAttributeToSelect('name')
                ->
addAttributeToSelect('is_anchor')
                ->
addAttributeToFilter('is_active'1)
                ->
addAttributeToFilter('level'2)
                ->
setOrder('position''ASC')
                ->
joinUrlRewrite()
                ->
load();
    
            
$productCollection Mage::getResourceModel('catalog/product_collection');
            
$productCollection->addCountToCategories($collection);
        
}
        
return $collection;
    
}

2. Duplicate the left.phtml file (app/design/frontend/default/default/template/catalog/navigation/left.phtml) into the same directory and name it left_home.phtml.

3. Make the following changes to left_home.phtml

Search and remove:

<?php if (!Mage::registry('current_category')) return ?>

Search for:

getCurrentChildCategories()

Replace with:

getMainCategories()

4. Call the new left_home.phtml template in the Custom Design of the Home page.

CMS > Manage Pages > Click on Home page > Custom Design > Set the Layout field to “2 columns with left bar” or “3 columns” (if using the default install) and add the following code to top of the Layout Update XML textarea:

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

Have a look at your home page, if all went well you will see the added menu in the left column. If you are using the default install, you will also notice the blocks that used to be in the left column are now appearing above the center column content. You can remove them in the Content textarea under the General Information tab.

That should be it.

Hope someone finds this useful.

Kind regards,

LL

Image Attachments
left_home.phtml.gif
 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Just updated the post above and thought someone might find it useful.

Kind regards,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
inyerface
Member
 
Total Posts:  31
Joined:  2008-08-29
 

Thanks for this LL! 

#4 did not work for me… so here’s what I did to fix it.

================
Go to CMS > Manage Pages > Click on Home page…
Add the following code to the Content textarea below

{{block type="catalog/navigation" template="catalog/navigation/left_home.phtml"}}
================

That did it for me!!
Thanks LL - very valueable post!

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Your welcome inyerface, glad you found it useful.

In step 4, I forgot to include that the Layout field needed to be set to “2 columns with left bar” or “3 columns”, if using the default install. By default this is set to “2 columns with right bar”, which might have been why it didn’t work for you. I’ve updated the post, thank you for your contribution.

Kind regards,

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hippo
Member
 
Total Posts:  34
Joined:  2009-02-10
 

Any idea if this would work with multiple stores?

I tried it and it shows main categories from all ‘root’ categories

 
Magento Community Magento Community
Magento Community
Magento Community
 
andij
Jr. Member
 
Avatar
Total Posts:  11
Joined:  2008-04-09
 

Thanks LL,

This worked for me using Ver 1.2.1.1 : )

Drew Jones

 
Magento Community Magento Community
Magento Community
Magento Community
 
bluent
Jr. Member
 
Total Posts:  8
Joined:  2009-05-13
 

Hi LL,

I am trying to implement this but I get the following error Fatal error: Call to a member function count() on a non-object

I have tried to replace

<?php if($_categories->count()): ?>
with
<?php if(count($_categories)): ?> as recommended in some places but that doesn’t work either.

It seems that it returns ‘0’ when i try to echo this variable.  this is happening on the home page and in the inner pages when I try. I would like to use the left navigation on the home page and on the catalog search/advance search result page.

Any help will be appreciated. I am using V 1.2.1.2

Thanks in Advance.

Tanya

 
Magento Community Magento Community
Magento Community
Magento Community
 
LL
Member
 
Total Posts:  47
Joined:  2008-09-23
 

Hi Tanya,

I can’t say off hand, I wish I could help but I’m afraid I’m working on a project deadline at the moment. In the mean time, hopefully someone else might be willing to help out.

Cheers!

LL

 
Magento Community Magento Community
Magento Community
Magento Community
 
Portnull
Jr. Member
 
Avatar
Total Posts:  1
Joined:  2008-09-23
 

hello,

i am having the same problems as tanya here. can anyone help please?
(why is it such an effort to get a simple navigation on the homepage anyway?)

cheers, moritz

 
Magento Community Magento Community
Magento Community
Magento Community
 
boxer1732
Jr. Member
 
Total Posts:  14
Joined:  2009-02-04
 

Portnull and Tanya,

I was able to get this to work on version 1.3.2.2.  All was fine other than step one.  Don’t insert at Line 67.  67 must have been for an older version.  Just insert it
after:

public function getStoreCategories()
{
$helper = Mage::helper(’catalog/category’);
return $helper->getStoreCategories();
}

Was line 80 on my navigation.php file.

Once that change was made, the error you mentioned went away and it worked perfectly - Thanks LL for the code - this is a great addition for us!

 
Magento Community Magento Community
Magento Community
Magento Community
 
walltoolsllc
Sr. Member
 
Total Posts:  146
Joined:  2008-08-21
 

Thanks for this post guys!  I followed the instructions and everything worked great.  I would really like to take the customization/display of the left hand navigation menu to the next level.  For me specifically, I would like to show a tiered left navigation menu on the left at all times.  Not sure how to do this, but this site has an excellent example of what I would like to do: http://shop.jack-wolfskin.de/bekleidung/hosen?gender=33

Any ideas on how to get a left nav like the example site above?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Sr. Member
 
Total Posts:  127
Joined:  2008-10-08
 

Hi LL,

your tip worked fine, thanks smile!

Just one problem, the same as Hippo, it’s getting all categories from the primary store, how do I make it call only the categories from this one?

Any help would be appreciated,

Best regards,
Leonel Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
sumon_cuet04
Jr. Member
 
Total Posts:  1
Joined:  2010-10-10
 

hi, now i want like this format in the home page left sidebar:

Main category1
-sub category1
-sub category2
-sub category3

Main category2
-sub category1
-sub category2
-sub category3

Main category3
-sub category1
-sub category2
-sub category3

Please can any one help me by step by step or giving any helpful link in this case asap.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerceoffice
Member
 
Avatar
Total Posts:  51
Joined:  2011-08-20
Russia
 

Check this menus:
Magento megamenu
Magento tabbed megamenu
in 99% they meet the needs of our clients.
If you need same menu for left or right sidebar, please contact with us

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2