Forum

Thread tagged as: Question

How do I load 'x' amount of items on same page on click of a button.

I'm trying to add pagination of sorts to my site, but instead of loading through to a new page I wanted to instead load say 3 items onto the bottom of the page, every time I click a 'load more' button. How would I go about achieving something like this using Perch?

I currently have...

<?php perch_content_custom('Entry List', array(
    'paginate' => true,
    'count'=>3
)); ?>

However I presume i won't need paginate => true for what I require?

Any help would be great, thanks

David Springate

David Springate 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The count option would need to be set dynamically, something like

$increment = 3;
$count = (int) perch_get('count', $increment);
perch_content_custom('Entry List', array(
    'paginate' => true,
    'count'=>$count,
));
echo '<a href="?count='.($count+$increment).'">Load more</a>';

Brilliant, thanks Drew!

Hi Drew,

I would like to achieve the same, but on a page that shows the menu listing of a restaurant which has three main product types, each with its variants.

In my code every product type is a separate region. I would like to show just the first five product variants per product type, and then have a load more button for the user to load the next 5 variants of a specific product type.

I tested the code above: it works fine, but it loads 5 more products for each variant – not just for the selected variant. How can I fix that?

Thank you in advance for your help,

I.