Forum

Thread tagged as: Question, Events

Getting the category images an event belongs to

Hi

in events app there are categories that you can setup and you can assign an image to each category.

I want to output each image for each category an event belongs to. How can i achieve that?

Thanks

Paul Langley

Paul Langley 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to use perch_events_event_categories() for that.

The first argument should be the slug or ID of your event.

but how would you do that in the template for event listing page?

i currently have <perch:events id="category_names" suppress="true" /> which lists the category names but i want the images assigned to those categories

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sure, you can do it on the page, and then pass the result into the template using PerchSystem::set_var()

https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/

Hi Drew

Sorry a bit lost as to how i would do this. In my php file i have ($year is defined separetely):

<?php perch_events_custom(array( 'filter' => 'eventDateTime', 'match' => 'eqbetween',
'value' => $year.'-09-01,'.$year.'-09-31', 'template' => 'events/listing/event-day.html' )); ?>

then my template is this:

<div class="event"> <div class="date"> <div class="day"> <perch:events id="eventDateTime" format="j" /> </div> <div class="month"> <perch:events id="eventDateTime" format="%b %Y" /> </div> </div> <div class="event-content">

<div class="title">
    <perch:events id="eventTitle" />
</div>

<div class="desc"> <perch:events id="eventDescHTML" html="true" /> </div>

</div> <div class="icons"> <perch:events id="category_names" /></div>

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, so this is a listing rather than an event detail view?

yes listing page

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Hmm, I can't think of a good way to do that with the Events app. It doesn't have some of the more advanced features of newer apps that would make it possible.

Perhaps:

<perch:events id="category_names" /> outputs all the names of the categories. If i called the image assigned to a category the same as the category name - i could output it.

But how can i loop through each category returned via <perch:events id="category_names" /> ?

This wont work because all categories are output at once - <img src="<perch:events id="category_names" />" />

Ta

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right - you can't. The way Events handles categories is really old and inconvenient.

Do you need the monthly calendar grid display? If not, you might not need Events at all.