Peter Knight Posted December 19, 2018 Posted December 19, 2018 Hi I'm unsure why my code below doesn't limit the results to 3 as specified. I have a Repeater Matrix (pro fields) on my page with 10 items and I want to echo out slides 2,3,4 only IE Start from the second slide and limit to the next 3 $items = $page->matrix_slider('start=1,limit=3'); foreach($items as $slide) { echo " <div class='uk-width-1-1 uk-width-1-3@s'> <div class='desk-wrap uk-text-left'> <a href='{$slide->url}'><img src='{$slide->images->first()->size(640,320)->url}'></a> <div class='desk-wrap-content'> <h4><a href='{$slide->url}'>{$slide->title}</a></h4> {$slide->body_mini}<br/> <a href='{$slide->url}' class='uk-button uk-button-primary'>Read more</a> </div> </div> </div> Thanks
dragan Posted December 19, 2018 Posted December 19, 2018 Try to use slice() $matrix = $pages->get(11203)->my_matrix; $items = $matrix->slice(1, 3); 3
Robin S Posted December 19, 2018 Posted December 19, 2018 3 hours ago, Peter Knight said: $items = $page->matrix_slider('start=1,limit=3'); There is no method call on the repeater matrix field value there - I think you meant to include ->find(): $items = $page->matrix_slider->find('start=1,limit=3'); That should work. 3
Peter Knight Posted December 19, 2018 Author Posted December 19, 2018 59 minutes ago, Robin S said: There is no method call on the repeater matrix field value there - I think you meant to include ->find(): $items = $page->matrix_slider->find('start=1,limit=3'); That should work. That was it. Thanks ?
Peter Knight Posted December 19, 2018 Author Posted December 19, 2018 3 hours ago, dragan said: Try to use slice() $matrix = $pages->get(11203)->my_matrix; $items = $matrix->slice(1, 3); That's pretty cool. And new to me too. I'll try that tomorrow and file under 'new stuff'. In the meantime, Robin's observation had me back on track.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now