Conditional display of Events+ shortcode?

I am making two lists of events — Past and Upcoming — per event category. I’m using [eab_archive] for the upcoming list, and [eab_expired] for the past ones, and the following shortcode template to display the list:

<?php foreach ($events as $event) { ?>
<?php $event = $event instanceof Eab_EventModel ? $event : new Eab_EventModel($event); ?>
<article class="eab-event <?php echo eab_call_template('get_status_class', $event); ?>" id="eab-event-<?php echo $event->get_id(); ?>">
<div class="event-listing">

<span class="event-listing-thumbnail"><?php echo $event->get_featured_image(); ?></span>

<span class="event-listing-title"><?php echo $event->get_title(); ?></span>
<span class="event-listing-meta"><?php echo eab_call_template('get_archive_content', $event); ?></span>

<span class="event-listing-excerpt"><?php echo $event->get_excerpt_or_fallback(200); ?></span>
</div>
</article>
<?php } ?>
</section>

I would like each list to have a title of Upcoming Events or Past Events, which displays only IF there are actually events in the loop.

At present, I have to put the title into the context of my page, and it displays all the time. This is OK for the “past events” list, because there are always past events. But there are not always upcoming events for every category. So when there are no upcoming events, the shortcode just returns nothing, so I’ll get something like this:

Upcoming Events

Past Events

* Event 1

* Event 2

* Event 3

I would like to either show either

(A) a graceful (custom) error message (e.g., “There are no upcoming events in this category, please see <here> for other opportunities to connect.”:wink:, or…

(B) nothing at all, not even a title.

In other plugins, I’ve seen something like this implemented within the shortcode itself, where you can specify an argument e.g., [shortcodexxx category=”Name or ID” title=”Upcoming Events” display=”auto”] so the title is displayed (or not) automatically, based on whether events actually exist in this particular category.

I tried using the CSS “content” property with the shortcode “class” argument, like this:

[eab_archive lookahead=yes weeks=25 category="107" class="auto-title-upcoming" template="event-list-with-thumbnails"]

Then I put this in CSS:

.auto-title-upcoming::before {
content: " Join us for this Upcoming Event";
color: white;
}

section.auto-title-upcoming {

background-color: #368a8a;
padding: 15px !important;
border-radius: 10px;
}

It looks great….until there is no upcoming event in that category! Then it degrades poorly, showing the text “Join us for this upcoming event” from the “content” property against the background color — but with no event listed. :slight_frown:

It seems there must be some way I can sneak an “if” statement in here, so that this whole thing only displays IF there is an event. I could probably run something using the ExecPHP plugin, but it’s not my favorite option.

Any ideas or suggestions?

Thanks!