Forum

Thread tagged as: Question, Problem, PayPal

Loading 'x' amount of shop items on the same page with a load more button?

I have posted a question on something similar before about how to load 'x' amount of items on the same page on click of a button. The answer that Drew provided here I have tried implementing in another instance in a shop however it isn't quite working the same way. This is my code at the moment...

<?php 
$increment = 6;
$count = (int) perch_get('count', $increment);
perch_shop_products_by_category('shop', array(
'paginate' => true,
'count'=>$count,
)); ?>

I'm trying to get it so that it shows 6 items on the shop homepage initially with a load more button underneath which will load 6 more when clicked on the same page without reloading the page, this code above is currently taking my original 6 items and paginating them 1 per page across 6 pages with a next/prev button.

Any idea where I'm going wrong here? Much appreciated!

David Springate

David Springate 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you included the $count+$increment to increment the count each time?

Do you mean:

echo '<a href="?count='.($count+$increment).'">Load more</a>';

I forgot to add that into my question but that is included so all in all its:

<?php 
$increment = 6;
$count = (int) perch_get('count', $increment);
perch_shop_products_by_category('shop', array(
'paginate' => true,
'count'=>$count,
)); 
echo '<a href="?count='.($count+$increment).'">Load more</a>';
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You don't want to use pagination - that will break things.

If you need to load it without the page reloading, you'll have to do that with JavaScript.