Magento – How to move the Layered Navigation on the Search Results page

layoutPHPxml

I'm trying to move the layered navigation block from the left sidebar to a div in my /catalog/product/list.phtml

I did this successfully in my product category view, by adding getChildHtml('catalog.leftnav') ?> to /catalog/product/list.phtml. And then in local.xml I added

<catalog_category_layered>
  <!-- remove from left block -->
  <reference name="left">
    <action method="unsetChild">
      <child>catalog.leftnav</child>
    </action>
  </reference>

  <!-- add as child to product list block -->
  <reference name="product_list">
    <action method="insert">
      <child>catalog.leftnav</child>
    </action>
  </reference>
</catalog_category_layered>

So the question is, how do I do this for the search results view? Both pages include /catalog/product/list.phtml. I tried to do this in local.xml:

<catalogsearch_result_index>
  <!-- remove from left block -->
  <reference name="left">
    <action method="unsetChild">
      <child>catalogsearch.leftnav</child>
    </action>
  </reference>

  <!-- add as child to product list block -->
  <reference name="product_list">
    <action method="insert">
      <child>catalogsearch.leftnav</child>
    </action>
  </reference>

</catalogsearch_result_index>

But then the layered navigation block just disappeard from the search results page. I tried a few other combinations of things in the layout.xml file, but I'm just not knowledgable enough in Magento layouts to know what to do here. Can someone please point me in the right direction?

Thanks!

Best Answer

The problem is that the name of the product list is different on the category page as on the search results page.

  1. Category: product_list
  2. Search results: search_result_list

So with this in mind the following code should work for you

<catalogsearch_result_index>
    <!-- remove from left block -->
    <reference name="left">
        <action method="unsetChild">
            <child>catalogsearch.leftnav</child>
        </action>
    </reference>

    <!-- add as child to product list block -->
    <reference name="search_result_list">
        <action method="insert">
            <child>catalogsearch.leftnav</child>
        </action>
    </reference>

</catalogsearch_result_index>