Jonathan Lahijani Posted June 16, 2015 Share Posted June 16, 2015 I have a page X with page-field called "listings". I want to paginate the listings on page X, but this seems not to work. Normally it would work fine if the thing that was to be paginated was wasn't coming from a Page select field. Here's what I have: <?php $listings = $page->listings->find("limit=2"); // this is not friendly to paginator it seems //$listings = $pages->find("parent=/listings/,template=listing,limit=2"); // this would work, but not what i want because it's not pulling the specific data i need... i want it come from a page field as shown in the above line. $pagination = $listings->renderPager(); ?> <?php include "./_head.php"; ?> <main class="main" role="main"> <?php if(count($page->listings)): ?> <div class="container"> <?php foreach($listings as $listing): ?> <?php wireIncludeFile("_listing-slab-item", array( 'listing' => $listing, )); ?> <?php endforeach; ?> <?php echo $pagination; ?><!-- this outputs nothing --> </div> <?php endif; ?> </main><!-- /.main --> <?php include "./_foot.php"; ?> To be sure, I did enable page numbers on my template file. Link to comment Share on other sites More sharing options...
tpr Posted June 16, 2015 Share Posted June 16, 2015 In a similar situation I grabbed page IDs first and then the pages, like this: // get all children pages ID $works = $page->children('artist!=null')->artist('|'); // get all artists with ID $t->allArtists = wire('pages')->find("id=$works, sort=date_birth"); It needs PW 2.6 or newer to work (because of "artist('|')"). I'm also interested in a more elegant way if there's any. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 16, 2015 Share Posted June 16, 2015 $page->listings returns a PageArray and PageArray::find doesn't work out of the box with pagination. Either set the start/limit/total values manually or use $pages->find() or $page->children(). Both of those will set these values automatically. Edit: Quick hack around. $listings = $page->listings->find("limit=2"); $listings = $pages->find("id=$listings"); 1 Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted June 16, 2015 Author Share Posted June 16, 2015 @LostKobrakai: I tried the code you posted but it didn't seem to work. @tpr: I tried your approach and it did work. The result: $listings = $pages->find("parent=/listings/,template=listing,limit=2,id=".$page->listings->id('|')); 1 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