Magento – Magento 2 Homepage as a Category

category-productshomelayoutmagento2

Is there a way to make the home page display as the default category? I don't want to use the cms widget, I want the customer to be able to sort and refine the products displayed. I thought I could do something like this:

<referenceContainer name="columns.top">
        <container name="category.view.container" htmlTag="div" htmlClass="category-view" after="-">
            <block class="Magento\Catalog\Block\Category\View" name="category.image" template="Magento_Catalog::category/image.phtml"/>
            <block class="Magento\Catalog\Block\Category\View" name="category.description" template="Magento_Catalog::category/description.phtml"/>
            <block class="Magento\Catalog\Block\Category\View" name="category.cms" template="Magento_Catalog::category/cms.phtml"/>
        </container>
    </referenceContainer>
    <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                <container name="category.product.list.additional" as="additional" />
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Framework\View\Element\Template" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                    <!-- The following code shows how to set your own pager increments -->
                    <!--
                        <action method="setDefaultListPerPage">
                        <argument name="limit" xsi:type="string">4</argument>
                    </action>
                    <action method="setDefaultGridPerPage">
                        <argument name="limit" xsi:type="string">3</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">list</argument>
                        <argument name="limit" xsi:type="string">2</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">list</argument>
                        <argument name="limit" xsi:type="string">4</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">list</argument>
                        <argument name="limit" xsi:type="string">6</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">list</argument>
                        <argument name="limit" xsi:type="string">8</argument>
                    </action>
                    <action method="addPagerLimit" translate="label">
                        <argument name="mode" xsi:type="string">list</argument>
                        <argument name="limit" xsi:type="string">all</argument>
                        <argument name="label" xsi:type="string">All</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">grid</argument>
                        <argument name="limit" xsi:type="string">3</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">grid</argument>
                        <argument name="limit" xsi:type="string">6</argument>
                    </action>
                    <action method="addPagerLimit">
                        <argument name="mode" xsi:type="string">grid</argument>
                        <argument name="limit" xsi:type="string">9</argument>
                    </action>
                    <action method="addPagerLimit" translate="label">
                        <argument name="mode" xsi:type="string">grid</argument>
                        <argument name="limit" xsi:type="string">all</argument>
                        <argument name="label" xsi:type="string">All</argument>
                    </action>
                    -->
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
            </block>
        </block>
        <block class="Magento\Cookie\Block\RequireCookie" name="require-cookie" template="Magento_Cookie::require_cookie.phtml">
            <arguments>
                <argument name="triggers" xsi:type="array">
                    <item name="compareProductLink" xsi:type="string">.action.tocompare</item>
                </argument>
            </arguments>
        </block>
    </referenceContainer>
    <referenceBlock name="page.main.title">
        <arguments>
            <argument name="id" xsi:type="string">page-title-heading</argument>
            <argument name="add_base_attribute_aria" xsi:type="string">page-title-heading toolbar-amount</argument>
        </arguments>
        <block class="Magento\Catalog\Block\Category\Rss\Link" name="rss.link" template="Magento_Catalog::category/rss.phtml"/>
    </referenceBlock>

Into app/design/frontend/Company/Theme/Magento_Theme/layout/cms_index_index.xml

No luck. Any ideas?

Best Answer

Setting Category Page as Home Page in Magento 2 is quite straightforward as Magento1.

You can set Default Web URL as "catalog/category/view/id/catId".

Replace catID with your desired category ID.

Setting Category Page as Home Page in Magento 2

I hope this will help you. If any one found even better way of doing this, please let me know.

Related Topic