Ask us a question!

Web Moves Blog

Web Moves News and Information

12
Jun
2015

Specify Grid or List mode on a per category basis in Magento

Magento LogoMagento is an incredibly flexible ecommerce platform. However, even with all the flexibility it offers, it can still be a challenge to make it bend to your will.

Recently, I needed to have a few specific categories show the products in grid mode, while all the other categories show products in list mode. This should be straightforward since the products that appear on a Magento category page can appear in either a vertical list, or in a grid. And, depending on how Magento is configured, the user can choose which view to display the products in.

Default magento list mode

The default List Mode in Magento

Nevertheless, while magento does provide a “List Mode” option that specifies how the products should be shown on a category page, this option applies to the entire catalog. So, unfortunately, it’s pretty much one or the other and there is no simple way to specify the list mode on a per category basis.

One not so simple way around this is to provide a “Custom Layout Update” in the Custom Design tab of the category to specify which mode product should display in. For example, the following code overrides Magento’s default “List Mode” setting and displays the products in a grid for the category.

While this approach works, it has a couple of problems:

  1. Normal users can’t be expected to enter XML. It’s hard to remember, error prone, and it’s just plain messy.
  2. If you give users the option to choose to display list or grid, then they won’t be able to switch between the views.

So doing the “Custom Layout Update” just wasn’t a feasible approach for me. I looked around for other ways to accomplish this, but it seemed like the easiest, most user-friendly, way was to just write a module to give the user an option to select which list mode a category should have. So I did just that and whipped up a little module I call DefaultCatView.

DefaultCatView is a Magento module that solves the above problem. It allows you to set the default product list mode (grid or list) on a per category basis. I put it on github in case it helps anyone else who needs this functionality in magento. You can download it here.

List mode per category

Installing it is simple. Either unzip it or upload it to your Magento webroot directory. After doing so, be sure to refresh Magento’s cache under System > Cache Management. After logging out and then logging back in, you will now have a List Mode option on the “Display Settings” tab of each category.