Removing Pager and Sorter Elements on Magento Home Page
As a senior developer, I often encounter situations where clients want to customize their Magento store’s homepage layout. One common request is to remove certain elements like the pager and sorter while keeping others intact.
The Current Setup
Let’s start by understanding your current setup. You have managed to display products from category ID 35 on your home page using the catalog/product_list block. However, you want to remove some specific elements that are currently visible in the layout.
<block type="catalog/product_list" category_id="35" column_count="4" template="catalog/product/list.phtml">
Identifying the Elements to Remove
From your description and attached image, you want to remove:
- The “Show” dropdown (first element)
- The “Page 1 of X” text and pagination links (second element)
- The sorting options (third element)
The remaining elementsâthe actual product listâshould remain visible.
Step-by-Step Solution
To achieve this, we need to modify the layout XML file for your CMS page. For simplicity, I’ll assume you’re using a custom page layout that extends 2columns-left.phtml.
- Access the Layout Update File
Navigate to
app/design/frontend/<your-theme>/layout/cms_page.xmland add the following code inside the<reference name="content">section:
<remove name="catalog.product_list.toolbar" />
<remove name="catalog.product_list.sorter" />
- Explanation of the Code
catalog.product_list.toolbar: This removes the pager and pagination links (elements 1 and 2 in your image).catalog.product_list.sorter: This removes the sorting options dropdown (element 3).
Keeping the Product List Visible
The product list itself is defined by the catalog/product_list block in your CMS page’s content. Since we haven’t removed this block, it will remain visible.
Final Touches and Testing
After making these changes, clear your cache using Magento’s built-in clearing tools or a command like:
bin/magento cache:clean
Then, navigate to your homepage to see the results. The pager, sorter, and specific pagination text should now be removed while keeping the product list visible.
Conclusion
Removing specific layout elements in Magento requires a combination of understanding the theme structure, identifying the element names (usually found in app/design/frontend/<your-theme>/layout/catalog.xml), and applying appropriate removal code in your custom layout XML file.
This approach ensures that you can still display products on your home page while maintaining a clean, uncluttered look by removing unnecessary elements. If you need further assistance with Magento development or want to explore more advanced techniques like creating custom layouts or using page builders, feel free to check out LaravelCompany’s Magento services.
Remember, always backup your files before making significant changes and test thoroughly on a staging environment before deploying to production.