How can i set continue load product on collection page without go to next page.

Solved
Embey
Excursionist
34 1 0

Hi community, can you help me with this.

I want to load product without going to next page.

Thank you

Replies 39 (39)
D-SOKO
Tourist
8 0 1

The code snippets are cut off. Can you please provide the full snippet? Thanks.

Jasoliya
Shopify Expert
4649 600 1166

this code work for debut theme not for any other,

Want to modify or custom changes on store hire me.
Email: jasoliyabrijesh123@gmail.com Or WhatsApp, Try our Free app for bundle page.
Want to get Free review and advice for sale on store ?? just text me here
AMarx_
New Member
2 0 0

Hi,

 

I implemented the code for collection-template.liquid but the 'Load More' button is not centered on the page, it is on the left. Can you please let me know how to fix this? 

 

Thanks in advance! 

 

Austin

Chicafull
Excursionist
11 0 5

 

Hi @Jasoliya, thanks for everything. The load more botton works perfectely but I have two issues: 1. I still have those arrows which allow you to change the page to see more products, and 2. My load more botton is on my left, and I saw that you sent a code to solve this problem but I don´t know where I have to put it exactely.  Can you help me? 

This is my website link:  https://fullofgrace.com.co/collections/aretes

I really will apreciate your help

Chicafull
Excursionist
11 0 5

@Jasoliya I worked on that and now I´ve solved all those issues, but I have a problem, at the end of the last "load more" there is still a button, but nothing loads because all products of that collection are already shown. What should I do? 

Thanks. 

Jasoliya
Shopify Expert
4649 600 1166

Hi

You have to follow proper way it work, if you miss anything it will not work and need code check whats affecting. cant say direct. 

Want to modify or custom changes on store hire me.
Email: jasoliyabrijesh123@gmail.com Or WhatsApp, Try our Free app for bundle page.
Want to get Free review and advice for sale on store ?? just text me here
Chicafull
Excursionist
11 0 5

Hi @AndyBerlin, you can replace the second code for this one, it worked for me:

$('.js-load-more').on('click', function(){
var $this =$(this),totalPages = parseInt($('[data-total-pages]').val()),currentPage = parseInt($('[data-current-page]').val());
$this.attr('disabled', true);
$this.find('[loader]').removeClass('hide');
currentPage = currentPage+1;
var nextUrl = $('[data-next-url]').val().replace(/page=[0-9]+/,'page='+currentPage);
$('[data-current-page]').val(currentPage);
$.ajax({
url: nextUrl,
type: 'GET',
dataType: 'html',
success: function(responseHTML){
$('.grid--view-items').append($(responseHTML).find('.grid--view-items').html());
},
complete: function() {
if(currentPage < totalPages) {
$this.attr('disabled', false); $this.find('[load-more-text]').removeClass('hide'); $this.find('[loader]').addClass('hide');
} else {
$this.attr('disabled', true); $this.find('[load-more-text]').addClass('hide'); $this.find('[loader]').addClass('hide');
}
}
})
});

Chicafull
Excursionist
11 0 5

Hi @AMarx_ , you can replace the first code for this one: 

 

<input type="hidden" value="{{ paginate.next.url }}" data-next-url>
      <input type="hidden" value="{{ paginate.pages }}" data-total-pages>
        <input type="hidden" value="{{ paginate.current_page  }}" data-current-page>
        <div class="load-more_wrap" style="text-align: center; margin-top: 40px;">
          <script>console.log(collection.products.size);</script>
            <button class="btn js-load-more">
              <span load-more-text>cargar más</span>
              <span class="hide" loader>cargando...</span>
              </but>
AMarx_
New Member
2 0 0

@Chicafull Thanks! I figured this out, but now I am having a similar issue as to what you previously posted where the load more button doesn't go away once you get to the bottom of the page. In my case, it is also repeating the first page over and over and doesn't display any products that were previously on page 2. https://antheianyc.com/collections/plants 

 

Were you able to get your Load More button to go away?

HannanWaheed
New Member
2 0 0

I tired this code on debut theme seems like its getting the same first page products and loads them again and again so i update the code a little to make it work as it works for me

 <input type="hidden" value="{{ paginate.next.url }}" data-next-link>
    <input type="hidden" value="{{ paginate.pages }}" data-all-pages>
    <input type="hidden" value="{{ paginate.current_page  }}" data-this-page>
    <input type="hidden" value="{{ collection.url  }}" data-coll-url>
    <div class="load-more_wrap">
      <button class="btn js-load-more">
        <span load-more-text>Load more</span>
        <span class="hide" loader>
            <img src="{{ 'loader.gif' | asset_url }}"/>
        </span>
      </button>
    </div>

 

$('.js-load-more').on('click', function(){
  var $this =$(this),
      totalPages = parseInt($('[data-all-pages]').val()),
      currentPage = parseInt($('[data-this-page]').val()),
      datacollurl = $('[data-coll-url]').val();;
  $this.attr('disabled', true);
  $this.find('[load-more-text]').addClass('hide');
  $this.find('[loader]').removeClass('hide');
  var nextUrl = $('[data-next-link]').val();
  var current_page_new = currentPage + 1;
  var next_coll = currentPage + 2;
  //alert(current_page_new)
    //return false;
  $.ajax({
    url: nextUrl,
    type: 'GET',
    dataType: 'html',
    success: function(responseHTML){
      $('[data-next-link]').val(datacollurl + "?page="+next_coll);
      $('[data-this-page]').val(current_page_new);
      $('.grid--view-items').append($(responseHTML).find('.grid--view-items').html());
    },
    complete: function() {
      if(current_page_new < totalPages) {
         $this.attr('disabled', false); $this.find('[load-more-text]').removeClass('hide'); $this.find('[loader]').addClass('hide');
      } 
      if(current_page_new >= totalPages) {
         $this.find('[load-more-text]').text('Products Finished').removeClass('hide'); $this.find('[loader]').addClass('hide');
      } 
    }
  })
});
Shaheer03161
Tourist
8 0 2

Hi, sir i tried your code and it worked 

can you tell me the possible solution for after clicking it shows all products sudden as i attached the reference link below

https://www.ninelineapparel.com/collections/mens-apparel

if you can help me

 

Jasoliya
Shopify Expert
4649 600 1166

This instruction is for debut theme so you can take idea. or need custom code for other theme.

 

Want to modify or custom changes on store hire me.
Email: jasoliyabrijesh123@gmail.com Or WhatsApp, Try our Free app for bundle page.
Want to get Free review and advice for sale on store ?? just text me here
GetOrchard
Excursionist
34 2 5

I am using Debut and this does not work for me. When I click Load More nothing happens and I get an error: "Uncaught ReferenceError: $ is not defined"
for theme.js

$('.js-load-more').on('click', function(){
  var $this =$(this),
      totalPages = parseInt($('[data-all-pages]').val()),
      currentPage = parseInt($('[data-this-page]').val()),
      datacollurl = $('[data-coll-url]').val();;
  $this.attr('disabled', true);
  $this.find('[load-more-text]').addClass('hide');
  $this.find('[loader]').removeClass('hide');
  var nextUrl = $('[data-next-link]').val();
  var current_page_new = currentPage + 1;
  var next_coll = currentPage + 2;
  //alert(current_page_new)
    //return false;
  $.ajax({
    url: nextUrl,
    type: 'GET',
    dataType: 'html',
    success: function(responseHTML){
      $('[data-next-link]').val(datacollurl + "?page="+next_coll);
      $('[data-this-page]').val(current_page_new);
      $('.grid--view-items').append($(responseHTML).find('.grid--view-items').html());
    },
    complete: function() {
      if(current_page_new < totalPages) {
         $this.attr('disabled', false); $this.find('[load-more-text]').removeClass('hide'); $this.find('[loader]').addClass('hide');
      } 
      if(current_page_new >= totalPages) {
         $this.find('[load-more-text]').text('Products Finished').removeClass('hide'); $this.find('[loader]').addClass('hide');
      } 
    }
  })
});
Kostop19
New Member
1 0 1

 

A solution for Dawn theme

<load-more class="load-more_wrap" 
      data-next-url="{{ paginate.next.url }}" 
      data-current-page="{{ paginate.current_page  }}" 
      data-total-pages="{{ paginate.pages }}" 
      data-page-size="{{ paginate.page_size }}"
      data-total-items="{{paginate.items}}"
      > 
      <script>console.log({{ paginate | json }})</script>
      <div class="load-more_row">
        Items shown
      </div>
      <div class="load-more_row">
        <span load-items-count>{{ paginate.page_size }}</span> / {{paginate.items}}
      </div>
      <button class="load-more_row button button--secondary js-load-more" type="button">
        Load more
      </button>
    </load-more>
class LoadMore extends HTMLElement { 
  constructor(){
    super();
    this.addEventListener("click", this.loadMoreItems);
  }

  loadMoreItems() { 
   
    const loadMoreBtn = this.querySelector('[type="button"]');
    loadMoreBtn.setAttribute("disabled", true);

    let { currentPage, pageSize, nextUrl, totalItems } = this.dataset
    let nextPage = parseInt(this.dataset.currentPage) + 1
    
    fetch(nextUrl.replace(/page=[0-9]+/,'page='+ nextPage))
      .then(response => response.text())
      .then((responseText) => {
        const html = responseText;
        $('#main-collection-product-grid').append($(html).find('#main-collection-product-grid').html());
      }).catch((e) => {
        // handle error
        console.error(e);
      })
      .finally(() => {
        loadMoreBtn.removeAttribute("disabled");
        this.dataset.currentPage = parseInt(this.dataset.currentPage) + 1;
        
        let isLastPage = parseInt(totalItems) - (nextPage * parseInt(pageSize) ) < 0
        this.querySelector('[load-items-count]').innerHTML = isLastPage ? parseInt(totalItems) : nextPage * parseInt(pageSize)
        isLastPage && loadMoreBtn.setAttribute("disabled", true);
      });
  }
}

customElements.define('load-more', LoadMore);

 

YashG
New Member
6 0 0

Hey @Kostop19 ,

It's not working for the dawn theme. Can you please recheck the code again and also suggest that where the code should be implemented means in which file and at which point. I had implemented the code after the condition {%- if paginate.pages > 1 -%} in the main-collection-product-grid.liquid but the doenst't worked for me.

designrepo
Excursionist
48 0 4

It's not working for the dawn theme. Please share me perfect code.

Thanks!

designrepo
Excursionist
48 0 4

Thanks Jasoliya!!

This code work perfectly.

But one more thing. When I paste this code on multiple section and click for one section but load more all section. 

Please see the attached.

Screenshot_30.png

 

Please help me for multiple section on same page.

 

 

Natzukofront
New Member
2 0 0

Hi @Jasoliya,

I am using Debut theme and i followed every step of what you said.
I have customized my Collection page before and i have 2 popular collection showing before the main collection.
When clicking on "load more" i want to show every prduct of the main collection but not on the 2 popular collection. 
The code is working except that when i clicked on "load more" it duplicate my first popular collection on the three collection at the same time.
Any help would be much appreciated here ! 
here is my page : https://geek-art.fr/collections/tableaux-naruto

PrezencaGroup
Shopify Partner
1 0 0

This is working for Dawn theme. But keep in mind to change #main-collection-product-grid to your product list id if needed