Jump to content

Paginating Pages from Page Selector Field


Jonathan Lahijani
 Share

Recommended Posts

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

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.

  • Like 1
Link to comment
Share on other sites

$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");
  • Like 1
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...