Jump to content

Get a repeater from a page but limit results


SamC
 Share

Recommended Posts

I've got a testimonials page, now I wanted to print a few (say 4) to the homepage. So I managed to grab them all:

<div class='container'>
    <div class='row py-5'>
        <div class='col-sm-12 col-md-6 px-lg-5'>

        <?php
            $testimonials = $pages->get(1019)->testimonials; // how to limit here?
            $testimonials->shuffle();
            $firstTestimonial = $testimonials->shift();
        ?>
            <?php foreach($testimonials as $index => $testimonial): ?>
                
                <?php if($index == ceil(count($testimonials) / 2)): ?>
                    </div>

                    <div class='col-sm-12 col-md-6 px-lg-5'>
                <?php endif; ?>
                
                <h2 class='py-3'><?= $testimonial->title; ?></h2>
                <p><?= $testimonial->testimonialBody; ?></p>
                <p class="font-weight-bold">
                    <i><?= $testimonial->testimonialReviewee; ?>
                    - Review from <a href='<?= $testimonial->reviewSitePageRef->reviewSiteURL; ?>' target='_blank'><?= $testimonial->reviewSitePageRef->title; ?></a>
                    </i>
                </p>
            <?php endforeach; ?>
        </div>
    </div>
</div>

Problem is I've been reading through the docs and can't see a way of limiting the returned results (when using get, it returns a single page so I guess there's nothing to filter). If I were to use $pages->find I can use 'limit=4' in the selector but the testimonials aren't pages, they are a repeater on a single page, hence I thought $pages->get was a good idea.

Would it be better to use $page->get("field") or something like that instead, rather than getting the testimonials page itself?

Or this? http://cheatsheet.processwire.com/templates/template-properties/template-fields/

Any advice would be awesome, thanks.

 

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...