Item counting on search page of magento

Item counting on search page of magento

October 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Item counting on search page of magento

Customizing Magento Search Page Item Counting

Are you looking to display the total number of items found on your Magento search results page without using the default pager? You’re in the right place! In this guide, we’ll walk through a step-by-step solution to achieve exactly that.

Understanding the Default Magento Behavior

By default, when a customer searches for a product in your Magento store, the search results are paginated. This means they are broken down into multiple pages with a specified number of items per page (usually 10-20). The total item count is displayed at the top of each page using the standard pager layout.

However, there might be cases where you want to show the count without the default pagination style. Perhaps you prefer a more minimalist look or need to integrate with a custom theme that doesn’t use the typical Magento pager. In either scenario, we can override this behavior easily.

Overriding the Search Results Block

The first step is to create an extension to override the Magento_Theme module’s search_result.phtml template file where the search results are rendered. Here’s how you do it:

  1. Create a new module: Let’s call our module Magento_CustomSearch.

  2. Declarative configuration: In your etc/module.xml, make sure to list your dependencies correctly:

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magento_CustomSearch" setup_version="1.0.0">
            <sequence>
                <module name="Magento_Theme"/>
            </sequence>
        </module>
    </config>
    
  3. Override the template: Create a new directory structure under your module:

    app/code/Magento/CustomSearch/view/frontend/templates/catalog/search
    

    Copy over the search_result.phtml file from your Magento theme’s directory (e.g., Magento/blank). This will serve as our base template.

Customizing the Search Results

Now, let’s update the search_result.phtml file to display the total item count without using the pager block:

  1. Open your custom search_result.phtml.

  2. Locate this line of code (line 78 in the default search_result.phtml):

    <div class="toolbar">
        <div class="pager">
            <?php echo $block->getPagerHtml() ?>
        </div>
    </div>
    
  3. Replace it with this custom code:

    <div class="search-results-count">
        Found <?php echo $block->getSize(); ?> Result<?php if ($block->getSize() > 1) { echo 's'; } ?>.
    </div>
    
  4. Save the file.

Conclusion: Displaying Total Items on Search Results

With this customization, you’ve successfully overridden the default Magento search results behavior to display the total number of items found in a clean and straightforward manner.

Remember, always test your changes thoroughly before deploying them live, especially when modifying core template files like this one. If you have any issues or need further assistance, feel free to reach out to us at Laravel Company.

Happy coding!

Catalog Extensions Themes Configuration

Our network