1

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.

Display "per page" select box only when there is pagination

Adding a "paginated" class to the <body> tag would do the trick. How can I do that?

0

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>
        </label>
        <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 ?>
                </option>
            <?php endforeach; ?>
        </select>
        <span class="limiter-text"><?php /* @escapeNotVerified */ echo __('per page') ?></span>
    </div>
<?php endif; ?>

Are you getting the desired result?

0

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

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

to

<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">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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