Question

I found the answer to this for Magento 1.x, but I can't find a 2.0x solution.

On my category pages, before the products are shown, there is a huge image, "category-image".

Does anyone know where the phtml file is that loads this image?

Thanks so much!

Was it helpful?

Solution

You can find this in your theme

app\design\frontend\{packagename}\{themename}\Magento_Catalog\templates\category\image.phtml

If you don't find the file here then you can create your own with same name having content:

<?php
    $_helper    = $this->helper('Magento\Catalog\Helper\Output');
    $_category  = $block->getCurrentCategory();
    $_imgHtml   = '';
    if ($_imgUrl = $_category->getImageUrl()) {
        $_imgHtml = '<div class="category-image"><img src="' . $_imgUrl . '" alt="' . $block->escapeHtml($_category->getName()) . '" title="' . $block->escapeHtml($_category->getName()) . '" class="image" /></div>';
        $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
        /* @escapeNotVerified */ echo $_imgHtml;
    }
?>

and you can modify it as you want. :)

Magento uses fallback method so this file is initially placed in Magento_Catalog::view/frontend/templates/category/image.phtml
You can overwrite it in your theme.

OTHER TIPS

Go to vendor\magento\module-catalog\view\frontend\templates\category and look for file image.phtml. This file is responsible to display Category image before rendering products. You can override this file in your magento designed theme, and can modify as per your requirements.

Go to app/design/frontend/vendor/theme/Magento_Catalog/layout/catalog_category_view.xml and remove block with xml code

<referenceBlock name="category.image" remove="true"/>
<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. 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">
    <body>
        <referenceContainer name="sidebar.main">
            <referenceBlock name="category.image" remove="true"/>
        </referenceContainer>
    </body>
</page>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top