Peter Knight Posted October 19, 2018 Share Posted October 19, 2018 Hi guys A few pages on my site are required to output a random quote from a bunch of 5 which are associated with that page. IE About has 5 quotes Home has 5 quotes Company has 5 quotes Normally I'd just make a few child pages for each parent and give it it's own template. Using a selector to do that would be easy. However, I've decided to go down the route of adding each pages 5 quotes to a repeater field. I can output ALL the pages quotes using this... <?php foreach($page->one_liner_group as $one) { echo "{$one->one_liner}<p>"; }?> but I'm not so sure where to add (limit=1) and getRandom when using repeaters within a page. Thanks Link to comment Share on other sites More sharing options...
Klenkes Posted October 19, 2018 Share Posted October 19, 2018 How about: $random_quote = $pages->find('template=repeater_one_liner_group, sort=random, limit=1'); Sometimes I get the latest something this way (sort=-created) Link to comment Share on other sites More sharing options...
Peter Knight Posted October 19, 2018 Author Share Posted October 19, 2018 I could go that direction if I had separate sub-pages. But these quotes are repeaters within each page. Or did I misunderstand your approach? Link to comment Share on other sites More sharing options...
Soma Posted October 19, 2018 Share Posted October 19, 2018 $page->one_liner_group->getRandom(); 2 Link to comment Share on other sites More sharing options...
BitPoet Posted October 19, 2018 Share Posted October 19, 2018 It should be even more straight forward: <p><?= $page->one_liner_group->getRandom()->one_liner ?></p> The value of a repeater field is a RepeaterPageArray, which is just a slightly extended PageArray. Edit: @Soma beat me by a few seconds ? 2 Link to comment Share on other sites More sharing options...
Peter Knight Posted October 19, 2018 Author Share Posted October 19, 2018 Thank you! So straightforward when you see how. I got up at 5AM this morning to work on this project and thought I'd get a good 12 hours at it. Instead, I had computer and internet problems all day. At least I can wake up tomorrow AM (not at 5AM though) knowing I have this fixed ? Link to comment Share on other sites More sharing options...
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