Jump to content

[Share] Gallery Grid Number Pagination

Recommended Posts

Posted

Description: Show number pagination under Gallery Grid

image.png.0c98bdebc2f4194c34c067515d0fd6ef.png

If code doesn't work on your site, you can share site url, I will check again.

#1. Use this code to Page Header Injection (Page where you use Gallery Grid)

<div class="pagination"></div>
<style>
.pagination {
    margin-top: 20px;
}
.pagination span {
    cursor: pointer;
    padding: 5px;
    margin: 0 5px;
    border: 1px solid #ccc;
}
.pagination span.active {
    background-color: #007bff;
    color: white;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $('.pagination').insertAfter('.gallery-grid-wrapper');
    const itemsPerPage = 18; 
    const totalItems = $('.gallery-grid-item').length; 
    const totalPages = Math.ceil(totalItems / itemsPerPage); 
    
    $('.gallery-grid-item').hide().slice(0, itemsPerPage).show();
   
    for (let i = 0; i < totalPages; i++) {
        $('.pagination').append(`<span class="page">${i + 1}</span>`);
    }
   
    $('.pagination').on('click', '.page', function() {
        const pageIndex = $(this).text() - 1; 
       
        $('.gallery-grid-item').hide();
       
        const start = pageIndex * itemsPerPage;
        const end = start + itemsPerPage;
       
        $('.gallery-grid-item').slice(start, end).show();
       
        $('.page').removeClass('active');
        $(this).addClass('active');
    });
    
    $('.pagination .page').first().click();
});
</script>

image.png.a8b9bdc8287dc28129d9aab7b744d509.png

#2. You can change number of items/page here

image.png.1cc2d813a516ada19615c7d2633f083a.png

#3. You can change color, border,… here

image.png.9f63f3bbe2c7d65cea1a73cea10712a0.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • Replies 0
  • Views 422
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.