Forum

Thread tagged as: Question

Pagination by Month

I created a basic list of events in runway. Works perfectly and it's pulling the events for the current month without issue.

My question: How do I setup paginate to create "previous month" and "next month" links?

I tried looking at the old Events.app for pointers or clues, but it appears the functionality I'm after is in the app itself.

// Current Month's Events
perch_content_custom('Events', array(
                'template' => 'calendar/calendar.html',
                'sort' => 'eventDateTime',
                'sort-order' => 'ASC',
                'filter' => 'eventDateTime',
                'match' => 'eqbetween',
                'value' => date('Y-m-01 00:00:00, Y-m-31 23:59:59'),

            ));

// Grab previous month for layout variable
    $month_prev = date('m', strtotime('-1 month'));

// Set layout variable
 perch_layout('events.above.interior', [
     'event_month_prev' => $month_prev
   ]);

// Previous Month's Events
perch_content_custom('Events', array(
                'template' => 'calendar/calendar_previous_button.html',
                'sort' => 'eventDateTime',
                'sort-order' => 'ASC',
                'filter' => 'eventDateTime',
                'match' => 'eqbetween',
                'value' => date('Y-'$month_prev'-01 00:00:00, Y-'$month_prev'-31 23:59:59'),

            ));

Seth Girardin

Seth Girardin 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

date("Y-$month_prev-01 00:00:00, Y-$month_prev-31 23:59:59"),

Thanks for showing me the proper format. Works and pull the previous month. I guess this isn't going to work for $month_next which wouldn't account for the year changing in December. What's the proper way in that case?

For paging through the actual events I used code like this:

         // Finding the Next event
          perch_content_custom('Events', array(
              'template'   => 'calendar/event_next.html',
              'filter'     => '_order',
              'match'      => 'gt',
              'value'      => $title[0]['_sortvalue'],
              'sort'       => '_order',
              'sort-order' => 'ASC',
              'count'      => 1,
          ));

Real Question: How do you do the same as above, but for a month at a time, and not be dependant on the event itself using _order so you can view the entire previous month's dates?

Drew McLellan

Drew McLellan 2638 points
Perch Support

strtotime() deals with that as you have it. Include the year too.

$month_prev = date('Y-m', strtotime('-1 month'));

date("$month_prev-01 00:00:00, $month_prev-31 23:59:59"),

Great that works perfect. Now I have current month, previous month, next month all working on same page.

While I am on the current month, how can navigate to previous month? (or next, if dates allow)

I only want content for one month at a time.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm afraid I don't have the capacity to build this solution for you one question at a time! These are general PHP logic questions, so I'm sure there are much better places to get help.

Thank you for getting me this far. I appreciate it Drew. :)

Now that you can display current, next and previous month's on the page, I would probably approach this with PHP if statements that check for query strings in the URL. And add Next and Previous Month links based on the URL structure you choose.