Hiding pagination with one page of results

Can’t get pagination to hide when there’s only one page of results

I am using list load with the pagination option. I would like to hide the pagination numbers when there’s only one page of results. Currently, it looks like this.

I found a script that I thought at first worked, but it turned out it did not work (or only very sporadically) in Safari (desktop and mobile), and it also stops working if the page is revisited in Chrome or Firefox.

I’m sure there’s a more appropriate solution for this, but I don’t know what I’m doing and can’t figure it out.

I am unable to publicly post a share link. If needed, I can share this privately.

Grateful for any help with this. Thanks!

This is the script I was trying to use:


Hey @EllenG!

You can send me the links via DM so I can take a look.

1 Like

Thanks Pedro! Will do.

Hey @EllenG!

I just answered your DM try the solution and let me know how it goes!

1 Like

So far it’s working great! Thanks so much!

2 Likes

Great to hear that, Ellen!
Let me know if there’s anything else I can help you with. :smiley:

1 Like

The issue was resolved via DM.

For possible future cases, I’ll share the solution.

This script hides the pagination if there’s only one page of numeric buttons:

<script>
   window.FinsweetAttributes ||= [];
   window.FinsweetAttributes.push([
      'list',
      (listInstances) => {
         listInstances.forEach(instance => {
            const root = instance.el || instance.root || document;
            const pageButtons = Array.from(root.querySelectorAll('[fs-list-element="page-button"]'));
            if (!pageButtons.length) return;

            const numericCount = pageButtons
               .map(b => b.textContent.trim())
               .filter(t => /^\d+$/.test(t)).length;

            const pagination =
               pageButtons[0].closest('[role="navigation"], .w-pagination-wrapper, .pagination') ||
               root.querySelector('[role="navigation"], .w-pagination-wrapper, .pagination');

            if (!pagination) return;
            pagination.style.display = (numericCount <= 1) ? 'none' : '';
         });
      },
   ]);
</script>
2 Likes

Hi—

After working perfectly since I last contacted you, the script suddenly stopped working. The page number isn’t hiding anymore. Yikes!

Any help getting this fixed again would be hugely appreciated. Thanks!

(DM sent with links.)