Forum

Thread tagged as: Question, Events

Template showing how to display events grouped by month?

Just wondering if anyone has built a template displaying events grouped by month. I've looked through the documentation and the forum and don't see any answers to this. Not being a PHP developer, this is the sort of thing that frequently trips me up.

I'm looking to display events managed using the Events app like so:

January

11th - Ski Day

17th - Trip #2

February

7th - Ski Day

21th - Trip #2

etc.

Any help would be greatly appreciated.

Timothy Swan

Timothy Swan 0 points

  • 5 years ago

I did something similar using a custom-listing-day.php template:

<perch:before>
   <ul class="calendar"></perch:before>
      <li><perch:if different="eventDateTime" format="F">
         <h2 class="date"><perch:events id="eventDateTime" format="F" /></h2></perch:if><perch:if different="eventDateTime" format="l, jS M Y">
         <h3 class="date small"><perch:events id="eventDateTime" format="l, jS M Y" /></h3></perch:if>
         <ul>
            <li class="vevent small">
               <span class="time dtstart"><span class="value-title" title="<perch:events id="eventDateTime" format="c" />"><perch:events id="eventDateTime" format="%l:%M %p" /></span> - </span>
               <span class="event summary <perch:events id="category_slugs" />"><a href="<perch:events id="eventURL" />"><perch:events id="eventTitle" /></a></span>
            </li>         
         </ul>
      </li><perch:after>
   </ul></perch:after>
   <perch:noresults>
   There are currently no events.
   </perch:noresults>

and I called it like this:

<?php
                        $event = perch_events_custom(array(
                        'filter'=>'eventDateTime',
                        'match'=>'gte',
                        'value'=>date('Y-m-d'),
                        'count'=>6,
                        'sort'=>'eventDateTime',
                        'sort-order'=>'desc',
                        'template'   =>'events/listing/custom-listing-day.html',
                        ));
?>

Does that do the trick?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you order the events by date, you can display something when the year/month is different from the previous:

<perch:if different="eventDateTime" format="Y-m">
    ... output the month ...
</perch:if>

I mean custom-listing-day.html template.

Thanks Jane and Drew! I'll try your suggestions.

Hi Jane, Your solution worked perfectly--it was a real help seeing the code that Drew referenced in context.

Thanks so much, Tim