Jump to content

Pagination and limit on Repeater Field on Frontend


buster808
 Share

Recommended Posts

Hi,

I can view repeater content with a simple foreach loop. Can a limit be added with pagination to a repeater field?

Some help in the right direction would be great.

Thanks

foreach($page->feedback_repeat as $feed ) {
 
$content .= "<h2>{$feed->title}</h2>";
$content .= "<p>{$feed->feedback_body}</p>";
}
Link to comment
Share on other sites

$results = $pages->find('template=repeater_your_repeater_field, limit=10');

$content = $results->each(function($item) {
    $out = "<h2>{$item->title}</h2>";
	$out .= "<p>{$item->title}</p>";
    return $out;
});

$pagination = $results->renderPager();


d($content);
d($pagination);

 

  • Like 3
Link to comment
Share on other sites

11 hours ago, Zeka said:

$results = $pages->find('template=repeater_your_repeater_field, limit=10');

It's not quite that simple for a few reasons. Repeater pages are not directly accessible for non-superusers meaning that selector won't work for guests. So you'd need to specify "include=all", but then you'd also need to exclude any unpublished or "ready" repeater pages with "status!=unpublished". Also, the selector would match all repeater items from that field from all pages, when probably what is wanted is only items from one page. So then you'd need to match repeater pages under only one parent, maybe by building the name of the parent from "for-page-" plus the ID of the page you want the repeater items from.

But the simplest way and only marginally less efficient is to match by the IDs of the repeater pages in the field value:

$results = $pages->find("id=$page->feedback_repeat, include=all, limit=10");

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...