2

First and foremost, I know that you can change the default products shown on all category pages for Grid and List views in System > Catalog > Frontend.

What I want to do is change this setting for individual categories. Let's say my default products per page setting is set to 16, I want the ability to specify that an individual category should only show 12 per page instead. My current approach is to create custom list and toolbar templates, essentially re-loading the collection with a custom limit. I have to believe there is a more programatic way to do it but am just at a loss as to what to do.

3 Answers 3

8

Assuming that all your default values are set in "Products per Page on Grid Allowed Values" in Admin > system config > Catalog > Catalog > Frontend

Then go to

Admin > Category > Manage Category > {Select your Category} > Custom Design > Custom Layout Update

Add

<reference name="product_list_toolbar">
  <action method="addPagerLimit"><limit>20</limit></action>
  <!--action method="setDefaultGridPerPage"><limit>20</limit></action-->
  <!--action method="setDefaultListPerPage"><limit>20</limit></action-->
</reference>
3
  • This quasi-worked! I had to change the method to 'addPagerLimit'. If you'll update your answer I'll accept it. Thanks so much!
    – callmetwan
    Commented Sep 3, 2014 at 14:37
  • What would be solution in magento 2, also, I want it for different page layout, like 1column and 2column-left
    – Haris
    Commented May 4, 2023 at 11:34
  • for magento 2.4 it is from Admin > Stores > Configuration > Catalog > Catalog > Storefront Then change "Products per Page on List Allowed Values" For me this is the only thing I needed to modify
    – Amjed Omar
    Commented Oct 3 at 22:16
4

You can achieve this in many ways. I will show you two ways how you can achieve this.

Via Layout Updation

I think this is the fastest and cleanest way to achieve this. You need to set page size for individual cateogories. For each category, Magento generates a unique layout handle. It looks like CATEGORY_{id} (where id stands for category id).

With that in mind, suppose you want to change page size of category with id 13 to 15 and category with id 7 to 30. For this layout updation file looks like this.

File :app/design/frontend/<your_package>/<your_theme>/layout/local.xml

<layout>
    <CATEGORY_13>
        <reference name="product_list_toolbar">
            <action method="addPagerLimit"><mode>grid</mode><limit>15</limit></action>
            <action method="addPagerLimit"><mode>list</mode><limit>15</limit></action>
        </reference>
    </CATEGORY_13>
    <CATEGORY_7>
        <reference name="product_list_toolbar">
            <action method="addPagerLimit"><mode>grid</mode><limit>30</limit></action>
            <action method="addPagerLimit"><mode>list</mode><limit>30</limit></action>
        </reference>
    </CATEGORY_7>
</layout>

You are done. If you now load those category pages, you can see that their page size get changed. You can refer my answer on this thread for more details.

Programmatic Way

We are going to do exactly same thing that we do through layout updation here. For this first we need to observe the event controller_action_layout_generate_blocks_after. This event is a perfect place to observe, since it will allow us to change any block properties. That is what we need to do here. (Basically if you look the code above, we are actually change a property of a block with name product_list_toolbar). So our observer class should looks like this

<?php
class Namepace_Modulename_Model_Observer {

    /**
      *
      * Holds Categoy ids
      *
      * @var array
      *
    */
    protected $_categoryIds = array(13,7) ;

    /**
      *
      * Holds page Sizes
      *
      * @var array
      *
    */
    protected $_pageSize = array(
        13 => 15
        7  => 30
    ) ;

    /**
      *
      * Use to set Page Size
      *
      * @param Varint Object  | $observer
      * 
      * 
    */
    public function setPageSizeForCategory($observer)
    {
        $controller = $observer->getAction();
        $fullActionName = $controller->getFullActionName();
        $id = (int)$controller->getRequest()->getParam('id');

        //check whether current page is correspond to our special category. If not, returns
        if ($fullActionName == "catalog_category_view" && $id == in_array($this->_categoryIds)) {

            //check whether toolbar block exist or not
            $toolbar =  $controller->getLayout()->getBlock('product_list_toolbar');
            if($toolbar) {

                //sets page size to corresponding mode
                $listMode = $toolbar->getCurrentMode();
                $toolbar = $toolbar->addPagerLimit($listMode , $this->_pageSize[$id]);
            }

        }
        return;
    }
}

For more details, you can refer my blog post

Hope that helps

1
  • Can you set the default amount as well with the layout method?
    – odd_duck
    Commented Aug 29, 2017 at 13:26
0

I have sort of stumbled on a back office way of achieving this as I did not like the pagination SEO implications nor giving too much choice on top level categories with say 200 products.

If you create a CMS block withe the following code - where ## refers to the Cat ID of the category you wish to limit and then set that category's display settings to static block only and referencing the block as per below code then you will have more control over listings.

{{block type="catalog/product_list" name="product_list" category_id="##" column_count="3" count="9" limit="9" mode="grid" template="catalog/product/list.phtml"}}

It will need further tweaking as you will note the text "Items 1 to 12 of X total" on a page such as cordless phones listing could be confusing at times but I think it will work and be simple to implement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.