Forum

Thread tagged as: Question, Runway

Collection Items over multiple functions

I have a scenario where I need to output Collection items over two functions within my home page. I don't want to repeat items over the two templates. The first template displays the first 7 items, the second template displays the next 6 items and should be used for pagination.

Example

<If first page>

Display first 7 items in promoted style

<end if/>

Display next 6 items in normal style (with pagination)

First Function

<?php
    perch_collection('Blog', [
    'template'   =>'blog/_blog_list_big.html',
    'sort'       =>'date',
    'sort-order' =>'DESC',
    'count'      => 7,
    ]); 
?>

Second Function

<?php
    perch_collection('Blog', [
    'template'   =>'blog/_blog_list.html',
    'sort'       =>'date',
    'sort-order' =>'DESC',
    'count'      => 6,
    'paginate'   =>'true',
    'pagination-var'  => 'post-page',
    ]); 
?>

Some of the challenges

  1. How do I detect if I'm on the first page
  2. I know I can't use 'start' => 8 and 'pagination' => 'true' at the same time on the second template so can't begin the second function's items at item 8 with pagination

Any help advice would be appreciated.

Dan Lee

Dan Lee 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use the API to get an instance of Paging - that will then tell you which page you're on.

I'm not sure you'll be able to do anything about the start position and maintain the pagination.

If we can pin down the logic for making start and paginate work at the same time, I'm happy to look at implementing it. The tricky bit is figuring out when to obey the start option and when to ignore it.

Dan Lee

Dan Lee 1 points

Thanks Drew. The start and paginate working at the same time would be brilliant functionality to have - I can see the benefit for us in having flexible front end design.

One possible way of implementing what we need is using the "every" functionality. <perch:every></perch:every>

It should be possible to count the first 7 items so we can style them differently right?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Every counts the items in the current set, so would always start from 1 for every page.