Create a BootStrap accordion of upcoming events
This example lists a set of event dates on one page as an accordion. Each date is a collapsed row, and opening a row shows that date's description and booking form. It suits a course that runs on several dates, where visitors pick one. It uses a shortcode and placeholders only.
What you will build
A page with one [events_list] shortcode whose format is the markup of a Bootstrap 5 accordion.
Your theme must already load Bootstrap 5, both its CSS and its JavaScript. The accordion's open and close behavior comes from Bootstrap's script, so without it every row stays closed. Bookings must be enabled on the events, as described in Set up event bookings.
Steps
-
Create the events and give them something in common to list them by. The simplest is an event tag such as
spring-course. A recurring event works well here: create it once with its recurrence pattern, tag it, and each date becomes its own bookable event with the same tag. -
On each event, or on the recurring event, tick Enable registration for this event in the Bookings/Registration box and add a ticket.
-
Edit the page that will hold the list and add a Shortcode block (or, in a page builder, its shortcode widget) with the code below. Change
spring-courseto your tag. -
Publish the page and view it.
[events_list tag="spring-course" scope="future" limit="10" pagination="0" format_header="<div class='accordion' id='eventsAccordion'>" format_footer="</div>"]
<div class="accordion-item">
<h2 class="accordion-header" id="heading#_EVENTID">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse#_EVENTID" aria-expanded="false" aria-controls="collapse#_EVENTID">
#_EVENTNAME: #_EVENTDATES, #_EVENTTIMES
</button>
</h2>
<div id="collapse#_EVENTID" class="accordion-collapse collapse" aria-labelledby="heading#_EVENTID" data-bs-parent="#eventsAccordion">
<div class="accordion-body">
#_EVENTNOTES
#_BOOKINGFORM
</div>
</div>
</div>
[/events_list]
How it works
- The content between the shortcode tags is the format for one event, repeated for each.
format_headerandformat_footerare printed once, before and after, and hold the accordion's outer wrapper. Putting the wrapper there, and not around the shortcode, keeps the items as its direct children, which Bootstrap needs. #_EVENTIDprints the event's ID. It makes each row'sidattributes unique, and connects each button to its own panel throughdata-bs-target.- Every row starts closed: the button has the
collapsedclass andaria-expanded="false", and the panel has noshowclass.data-bs-parentmakes opening one row close the others. #_EVENTNOTESprints the event's description, and#_BOOKINGFORMprints its booking form, or the "bookings closed" or "fully booked" message when it can't be booked.
To list the dates of one recurring event without a tag, use recurrence="123" in place of the tag attribute, where 123 is the event ID of the recurring event.
Each #_BOOKINGFORM is a full form, so a long list makes a heavy page. Keep limit modest. If you only need a link to each date's own page, use #_EVENTLINK in place of the form.
Test it
- View the page. Each upcoming date is a closed row showing its name, date and time.
- Open a row. The description and booking form appear, and any other open row closes.
- Make a test booking from one row and check in Events then Bookings that it was recorded against the right date.
If rows don't open, Bootstrap's JavaScript isn't loaded on the page. If all rows open together, check that each id contains #_EVENTID and that the editor hasn't removed the data-bs- attributes.