Hiding Magento Toolbar Elements on Specific Category Pages
If you’re looking to customize your Magento store’s user experience by hiding irrelevant toolbar elements like “Sort By” and the “Show X Products” dropdown, you’ve come to the right place. In this post, we’ll guide you through the process of achieving this for a specific category page that displays new arrivals.
Understanding Your Current Setup
You have a home page redirecting to a custom category page which uses the Tridian New Arrivals code to display a collection of recently added products. The collection is sorted by the entity_id field in descending order, bypassing the default created_at sorting that sometimes doesn’t work as expected.
The current setup involves an override on the category page to filter and display only the desired product collection. This is a common approach for creating custom landing pages or special promotional sections within your Magento store.
The Challenge: Hiding Irrelevant Toolbar Elements
The main challenge here is that you want to remove certain toolbar elements, specifically the “Sort By” dropdown and the “Show X Products” selector, from this specific category page. These options are usually needed for browsing regular product catalogs but become redundant on a well-curated new arrivals page like yours.
The Solution: Magento Layout XML Overrides
To accomplish this, we’ll use Magento’s layout update feature to add an XML override that specifically targets the toolbar block on your custom category page. Here’s how it works:
-
First, create a new layout XML file in your theme directory under
app/design/frontend/%theme%/%package%/layout. For example, you might name itcatalog_category_view.xml. -
Inside this XML file, add the following block to target the toolbar on your specific category page:
<referenceContainer name="category.topsales">
<block type="catalog/product_list_toolbar" template="catalog/product/list/toolbar.phtml"/>
</referenceContainer>
Replace category.topsales with the name of your custom layout handle that’s used for this new arrivals category page.
- Now, you need to use Magento’s built-in XML block configuration to hide the unwanted toolbar elements:
<referenceBlock name="product_list_toolbar">
<action method="setTemplate">
<argument name="template" xsi:type="string">catalog/product/toolbar/new_arrivals.phtml</argument>
</action>
</referenceBlock>
In this step, we’re setting a custom template file new_arrivals.phtml for the toolbar block. This file should be located in your theme directory under app/design/frontend/%theme%/%package%/template/catalog/product/toolbar.
- Inside the
new_arrivals.phtmlfile, you can use PHP to hide or remove any unwanted elements from the toolbar:
<?php if (!$this->getAvailableSortByOptions()): ?>
<div class="sort-by">
<?php /* Hide the sort by dropdown */ ?>
</div>
<?php endif; ?>
<div class="sort-limits">
<?php if ($count != 0 && $count > $limit): ?>
<!-- Showing # of products -->
<?php if (is_string($count)): ?>
<span class="label"><?= /* @escapeNotVerified */ $count ?></span>
<?php else: ?>
<span class="label"><?= /* @escapeNotVerified */ $this->__('%s products', $count) ?></span>
<?php endif; ?>
<?php endif; ?>
<!-- Hide the "Show X Products" selector -->
</div>
In this example, we use PHP conditionals to hide the sort by dropdown if there are no sorting options available for your new arrivals collection. We also comment out the HTML code for the “Show X Products” selector.
- Save all files and refresh your Magento cache after making these changes. The unwanted toolbar elements should now be hidden on your custom category page.
Why This Approach Works
This method leverages Magento’s native layout and block configuration system to apply fine-grained control over how the toolbar is rendered on specific pages. By using a custom template file, we can modify the output of the toolbar block without touching any core files, ensuring our changes remain intact even after updates.
Conclusion: Streamlining Your Store’s User Experience
In this post, we demonstrated how to hide irrelevant Magento toolbar elements on a specific category page that displays new arrivals products. By following the XML override approach outlined above, you can create a more streamlined and focused user experience for your shoppers browsing these curated collections.
Remember, the key is to target the layout handle of your custom category page in the XML configuration file (step 2). This ensures that the toolbar element hiding logic only applies to this specific context within your store.
Don’t forget to check out our comprehensive Magento development services at LaravelCompany if you need further customization or assistance with your e-commerce platform. We specialize in delivering high-quality, performance-driven solutions tailored to meet the unique needs of modern online retailers like yourself.
Happy hiding those toolbar elements! Let us know if you have any other questions about Magento development or store optimization.