Do not display a "per page" select box, if products are not paginated

by Razvan Zamfir   Last Updated January 12, 2018 14:09 PM

I am working on a Magento 2.1.7 shop and I have created a child-theme of Magento Blank.

The products are 12 per page by default, but the user has the option to show 24 products per page.

Some (category) pages have less than 12 products, therefore, there is no pagination. I want, in such cases, the "per page" select box not to be displayed.

How can I do that?

Answers 2

In path/to/CustomTheme/Magento_Catalog/templates/product/list/toolbar/limiter.phtml I modified the line

<div class="field limiter form-inline pull-right">


<div class="field limiter form-inline pull-right <?php if ($block->getLastPageNum()==1) { echo 'hidden'; } ?>">

The code above adds the "hidden" CSS class to the "limiter" if the products are not paginated:

<div class="field limiter form-inline pull-right hidden">
Razvan Zamfir
Razvan Zamfir
January 15, 2018 15:20 PM

You could also try:

<?php if ($block->getLastPageNum() > 1): ?>
    <div class="field limiter form-inline pull-right">
        <label class="label" for="limiter">
            <span><?php /* @escapeNotVerified */ echo __('Show') ?></span>
        <select id="limiter" data-role="limiter" class="limiter-options form-control input-sm">
            <?php foreach ($block->getAvailableLimit() as $_key => $_limit): ?>
                <option value="<?php /* @escapeNotVerified */ echo $_key ?>"<?php if ($block->isLimitCurrent($_key)): ?>
                    selected="selected"<?php endif ?>>
                    <?php /* @escapeNotVerified */ echo $_limit ?>
            <?php endforeach; ?>
        <span class="limiter-text"><?php /* @escapeNotVerified */ echo __('per page') ?></span>
<?php endif; ?>

Are you getting the desired result?

April 17, 2018 08:49 AM

Related Questions

Pagination missing in Magento 2.1.9 category pages

Updated November 30, 2017 16:09 PM

Page controls not showing in toolbar

Updated March 16, 2017 11:09 AM

Pagination not working properly Magento 2

Updated April 15, 2017 05:09 AM