How to change layout of all category in magento to 1 column
-
12-04-2021 - |
Question
i have about 100 catgory in admin, is there way to change layout of all catgory to 1column
i can do it from backend,but doing one by one will take too much time, is there way to do it quickly
i tried to do it from layout file but it is not working, below is my code of xml file , still is see products as 1 column-left
Magento_Catalog/layout/catalog_category_view.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="div.sidebar.additional">
<block class="Magento\Cms\Block\Block" name="banner_left" after="recentproductslider">
<arguments>
<argument name="block_id" xsi:type="string">banner_left</argument>
</arguments>
</block>
</referenceContainer>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="breadcrumbscategory" template="Magento_Theme::html/breadcrumbscategory.phtml" before="-"/>
<block class="Magento\Framework\View\Element\Template" name="custom.text" template="Magento_Theme::html/custom-list-page.phtml" after="breadcrumbscategory"/>
</referenceContainer>
<referenceBlock name="catalog.leftnav" remove="true" />
<move element="category.view.container" destination="page.top" before="-"/>
<!-- <move element="breadcrumbs" destination="category.view.container" before="page.main.title"/> -->
<move element="page.main.title" destination="content" before="-"/>
<referenceContainer name="page.main.title" remove="1"/>
<referenceContainer name="breadcrumbs" remove="true" />
</body>
</page>
La solution
Maybe other modules rewrite that layout please check another module not conflict with it.
It is a bad habit to edit core files create the module and add the file to
app/code/Vendor/Modulename/view/frontend/layout/catalog_category_view.xml
add below code to file:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head></head>
<body></body>
</page>
After this, please clear cache using below command :
php bin/magento cache:flush
Another Way
The xml file you want to override is
/vendor/magento/module-catalog/view/frontend/layout/catalog_category_view.xml
So it should go in
app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_category_view.xml
Example override
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
</page>
Autres conseils
Create or open file app/design/frontend/[Theme-Package]/[theme]/Magento_Catalog/layout/catalog_category_view.xml
Change the following line:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
to:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">