I wanted something very similar - a list of related events (defined by an earlier created stash) that showed a chronological list of only the NEXT 'occurrence' of each event. I saw this thread, but being new to PHP couldn't follow the example because I didn't know how to extrapolate all the $data variable to where I could build up the actual HTML I wanted... so in case anyone else in my shoes finds this later on, I wanted to share my code that hopefully explains well enough for a noob:
<!-- Create array to hold data from each related event against the Event ID -->
<?php $events = array(); ?>
{exp:calendar:cal
date_range_start="today"
date_range_end="1 year"
pad_short_weeks="n"
enable="custom_fields"
event_id="{exp:stash:get name="stash_related_events"}"
dynamic="no"}
{events}
<!-- Populate array with individual event details - this will include all occurrences, but we'll remove duplicates in PHP -->
<?php $events['{event_id}'] = '{event_id}~~{event_title}~~{event_summary}~~{event_image:Medium}~~{event_location}~~{event_start_date format="%F %j, %Y"}~~{event_start_date format="%g:%i%a"}~~{event_end_date format="%F %j, %Y"}~~{event_end_date format="%g:%i%a"}'; ?>
{/events}
<!-- Reverse order of array because they're backwards for some reason (??) -->
<?php $events = array_reverse($events); ?>
<!-- Loop through each unique event_id in the array to get desired list -->
<?php foreach($events as $event_id => $event_data) :?>
<?php
// Extrapolate data in the array to have usable variables using ~~ as the delimiter
list($event_id, $title, $event_summary, $event_image, $event_location, $event_startDate, $event_startTime, $event_endDate, $event_endTime) = explode('~~',$event_data);
// Check for empty image
if ($event_image == "") { $event_image = "../../images/uploads/eventImages/_Medium/event-default.jpg"; }
// Format Date/Time entry
$event_dateTime = "";
if ($event_startDate == $event_endDate){
if ($event_startTime == "12:00am" && $event_endTime=="12:00pm"){
$event_dateTime="All day ".$event_startDate;
} else {
$event_dateTime=$event_startDate." from ".$event_startTime." to ".$event_endTime;
}
} else {
$event_dateTime="From ".$event_startDate.", ".$event_startTime." to ".$event_endDate.", ".$event_endTime;
}
// We could build up HTML inside PHP using either syntax below...
// echo "<h2>".$title."</h2>";
// echo "<h2>$title</h2>"; Same as above
?>
<!-- But instead we'll build up HTML here and insert variables where necessary -->
<div class="event item clearfix">
<h2><a href="../../events/event/<?php echo $event_id ?>"><?php echo $title ?></a></h2>
<h4 class="eventDateTime"><?php echo $event_dateTime ?></h4>
<div class="eventImage">
<a href="../../events/event/<?php echo $event_id ?>"><img src="<?php echo $event_image ?>" alt="<?php echo $title ?>" /></a>
</div>
<p>Location: <?php echo $event_location ?></p>
<p>Summary: <?php echo $event_summary ?><p>
</div>
<?php endforeach; ?>
{/exp:calendar:cal}
Hope this helps someone save the amount of time I spent on this!