Pagination with Custom Query—Past Events

The events archive page /events lists all the upcoming events. In this lesson, we will create an archive of the events that have taken place and are not shown on the /events page. To display past events, we will create a page titled Past Events.

Remember that pages are powered by the page.php theme file. If we want to create a page for a custom post type, we need to create a special file page-{$slug}.php. In case this file is missing, WordPress will use page.php as a fallback to display the page.

Past events page

Click the "Pages" option from the admin dashboard sidebar. Choose "Add New." The title of the page is Past Events Archive. For the Description custom field, we can say “Browse events that took place previously”. Publish the page without adding any content.

We want this page to have a different design than the other pages (like About Us or Contact Us) as it will be an archive of past events.

The template file to power this particular page can be created using its slug, /past-events-archive. In the theme folder, create a file page-past-events-archive.php and write a test message Hello from the past events archive. If we view the Past Events Archive page now, we should see this test message.

The past events page shows an archive of events that have taken place in the past so we can copy the design from archive-events.php and tweak it to meet our needs.

Page title and description

We have already provided the title and description when creating the page. The display_page_banner() function does not need any arguments.

Get hands-on with 1200+ tech skills courses.