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 6
Layered navigation at home page? 
 
lukas.w
Jr. Member
 
Total Posts:  3
Joined:  2008-02-22
Wroclaw, Poland
 

Hi guys,

if someone can tell me (already did it) how place layered navigation at home page?
I updated XML layout via CMS > Manage Pages > Homepage > Layout Update XML box:

<reference name="left">
    <
block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</
reference>

but when I reloaded home page an error occurred:
exception ‘Mage_Core_Exception’ with message ‘Cannot retrieve current category object’.

I tried to modify a core method getCurrentCategory() in core/Mage/Catalog/Model/Layer.php (I know that’s a bad idea, but I need a quick solution even if this prevent me from next release update), but I failed, because I didn’t know how to set up a root category as a current category.
Later, in test case, I set a current category to one under root (in this case category with id 31, in bold is my modification):

public function getCurrentCategory()
    
{               
        $category 
$this->getData('current_category');
        
       
[b] if(is_null($category))
        
{            
            $home_category 
Mage::getModel('catalog/category')->load(31);
            
$this->setData('current_category'$home_category);
            
$category $this->getData('current_category');
        
}[/b]
        
        
if (is_null($category)) {
            
            
if ($category Mage::registry('current_category')) {
                $this
->setData('current_category'$category);
            
}
            
else 
            
{                               
                Mage
::throwException(Mage::helper('catalog')->__('Cannot retrieve current category object'));
            
}
        }
        
return $category;
    
}
and now, layered navigation was successfully loaded at home page (exactly the same if I choose category with id 31 from top menu).
But when I hovered on generated links in navigation I saw strange thing,
link to category XXX was:
/cms/index/index/cat/4/
when correct link to the same category in normal flow (not at home page) is:
/catalog/category/view/cat/4/id/31/.

When I clicked in this short link (/cms/index/index/cat/4/) layered navigation correctly updated,
but not content of the page (should be list of products in current selected category, but system
load content of home page).

Someone knows what cause this behavior and how do I correct place and configure layered navigation at home page?

My Magento version: 0.7.15480

Lukas.
Thanks for any response.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lucian303
Member
 
Avatar
Total Posts:  74
Joined:  2008-03-03
 

I just tried it and it works, but it seems to only filter products within that category.The links work fine, but what I’d like to have happen is for those items to filter all the products in the store and just use that page to ‘promote products to the front page’. I tried to make another hidden category with all the products, but was unable to get this result. Otherwise filtering works well, however, it only works within that category. I guess I can try to put random products and just have all products show as part of that category but only a certain number to populate the front page, each time randomly, unless someone has some better ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
glaDiator
Member
 
Avatar
Total Posts:  65
Joined:  2008-03-17
 

Look at the post

http://www.magentocommerce.com/boards/viewthread/5500/

 
Magento Community Magento Community
Magento Community
Magento Community
 
lucian303
Member
 
Avatar
Total Posts:  74
Joined:  2008-03-03
 

I realized I had to change the function to this to work with the layout update on the first page:

public function getCurrentCategory()
    
{
        $category 
$this->getData('current_category');
        if (
is_null($category)) {
            
if ($category Mage::registry('current_category')) {
                $this
->setData('current_category'$category);
            
}
            
else {
                $category 
false;
                
$this->setData('current_category'$category);
            
}
        }
        
        
//added to make this work for front page:
        
if(is_null($category) || $category == false{            
            $home_category 
Mage::getModel('catalog/category')->load(8); //number must correspond to 'all products page' category
            
$this->setData('current_category'$home_category);
            
$category $this->getData('current_category');
            
//return $category;
        
}
        
//end addition

        
return $category;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
pastanislas
Member
 
Total Posts:  46
Joined:  2008-07-29
 

But when I hovered on generated links in navigation I saw strange thing,
link to category XXX was:
/cms/index/index/cat/4/
when correct link to the same category in normal flow (not at home page) is:
/catalog/category/view/cat/4/id/31/.

When I clicked in this short link (/cms/index/index/cat/4/) layered navigation correctly updated,
but not content of the page (should be list of products in current selected category, but system
load content of home page).

Hi, how do you get out of here ?
My url’s are like this http://www.mywebsite.com/cms/index/index/?price=26&#x2C;10
ans i’m sticking at the homepage :(
I’m on magento 1.1.3.
Thanks in advance

 
Magento Community Magento Community
Magento Community
Magento Community
 
lubiluk
Jr. Member
 
Total Posts:  4
Joined:  2008-07-21
 

I’ve found a way how to do it.

First, go to /app/design/frontend/default/default/template/catalog/layer and make a copy of file view.phtml named for example homeview.phtml. In this new file replace:

<?php echo $_filter->getHtml() ?>
with:
<?php echo str_replace("cms/index/index","ALLTHINGSCATEGORY",$_filter->getHtml()) ?>
where ALLTHINGSCATEGORY is a url key of category you want to have on homepage.
Thank’s to above things, links on homepage in layered navigation will be good.

Next, update XML layout via CMS > Manage Pages > Homepage > Layout Update XML box:

<reference name="left">
    <
block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/homeview.phtml"/>
</
reference>

And last important thing is to modify file /app/code/core/Mage/Cms/controllers/IndexController.php. On begining of method indexAction() add these lines (replace category id with yours ALLTHINGSCATEGORY id):

$categoryId 27// ID OF CATEGORY YOU WANT ON HOMEPAGE
            
            
$category Mage::getModel('catalog/category')
                ->
setStoreId(Mage::app()->getStore()->getId())
                ->
load($categoryId);

            if (!
Mage::helper('catalog/category')->canShow($category)) {
                
return false;
            
}
            
            Mage
::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId());
            
Mage::register('current_category'$category);
Enjoy layered navigation on home page smile.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael R
Jr. Member
 
Total Posts:  8
Joined:  2008-08-04
 

Thanks a ton for your hard work lubiluk. I’ve been looking for a good solution for this also and had planned a solution like your ALLTHINGSCATEGORY. You’ve saved me a lot of time. I’m going to try this out right away.

One thing that bothers me (although I may be naive here) is that making a new template type might cause problems when upgrading or changing themes. Is there no way to overwrite the template that is currently in use (I think it’s “.../template/cms/default/home.phtml") on the front page by putting a modified copy somewhere in our non-default template folder?

Edit: technically the core mod and template change should be worked into a module...... I’m not sure if it’s possible to change the layout xml directoly from the module so that would still be manual, but oh well…

 
Magento Community Magento Community
Magento Community
Magento Community
 
lubiluk
Jr. Member
 
Total Posts:  4
Joined:  2008-07-21
 

uhm yes, upgrading is problematic. In version 1.1.5 it stopped to work. After upgrade I had to modify /app/code/core/Mage/Cms/controllers/IndexController.php file because it was owerwritten. And line

<?php echo str_replace("cms/index/index","ALLTHINGSCATEGORY",$_filter->getHtml()) ?>
doesn’t work anymore. I replaced it with:
<?php echo str_replace(array('?','/?'),array('ALLTHINGSCATEGORY?','/ALLTHINGSCATEGORY?'),$_filter->getHtml()) ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
keithabt
Jr. Member
 
Total Posts:  13
Joined:  2008-09-08
 

lubiluk:

Im using version 1.1.6

Could you tell me what this is referencing ‘cms/index/index’ in

<?php echo str_replace("cms/index/index","ALLTHINGSCATEGORY",$_filter->getHtml()) ?>

Any help would be appreciated

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

I’m using the first method in this thread and it works except once you narrow it, it stays on the main page instead of going to the products it’s narrowed it down to - does anyone know why this might be happening and how to fix it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jelmo
Jr. Member
 
Total Posts:  28
Joined:  2008-08-15
 
sherrie - 24 September 2008 10:02 AM

I’m using the first method in this thread and it works except once you narrow it, it stays on the main page instead of going to the products it’s narrowed it down to - does anyone know why this might be happening and how to fix it?

Try to use the last update specified above. I’m running 1.1.6 and i got it working so it links perfectly from fronpage to a category.

The only thing i’m stuck at, is that the top menu is created of al the categories in the root category. Since i made an layer in between the root category and the actual categories, that category in between (to reference to with the layerd navigation) is the only thing showing up in de menu…

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Well the problem with that is if I put the code into the IndexController.php page like this:

public function indexAction($coreRoute null)
    
{

            $categoryId 
2// ID OF CATEGORY YOU WANT ON HOMEPAGE
            
            
$category Mage::getModel('catalog/category')
                ->
setStoreId(Mage::app()->getStore()->getId())
                ->
load($categoryId);

            if (!
Mage::helper('catalog/category')->canShow($category)) {
                
return false;
            
}
            
            Mage
::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId());
            
Mage::register('current_category'$category);
            
            
$pageId Mage::getStoreConfig('web/default/cms_home_page');
        if (!
Mage::helper('cms/page')->renderPage($this$pageId)) {
            $this
->_forward('defaultIndex');
        
}
    }

Then I get a blank front page. If I leave that code out I get no errors but when you select an option from the layered nav it gets a bad url. http://www.minervapromotions.com/techusa

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Does anyone have either of these two methods fully functioning?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tykes123
Jr. Member
 
Total Posts:  5
Joined:  2008-09-25
 

i used the methods described by lukas.w and the FIRST post by lubiluk in v 1.1.6 and i had a layered navigation on the first page that narrowed down but no products were visible in the middle...the center area stayed at the home page. i tried it again in v 1.1.4 and i just got a blank home page. I also would like to know if anyone has figured out how to get a functioning layered navigation

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hercilio Costa
Member
 
Total Posts:  59
Joined:  2008-07-15
 

I have that method working, but i have the links problem to. Anyone know how to solve that link problem??

The links are like this: /index.php/ROOTCATEGORY?categoria=94

ROOTCATEGORY is the URL key from my ALLTHINGSCATEGORY

EDIT: One thing that bothers me, is that this method doesn’t work with a root category, it only works with a subcategory. That isn’t a problem if the “Root Subcategory” doesn’t appear in the menu bar.

Is there a way to put this working with a Root Category or to make the Root Subcategory disapear from the menu bar??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hercilio Costa
Member
 
Total Posts:  59
Joined:  2008-07-15
 

The links problem is solved:

I have the wrong URL Key in the homeview.phtml.

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