22 - Displaying Related Events on Ministry Pages

One distinct advantage of using native ExpressionEngine functionality for a church event calendar is that the event information can be pushed and pulled to different parts of the site.  In this chapter I’ll show how to display upcoming events on the Ministry detail pages.  New EE functionality this chapter covers will be the reverse related entries tag.

Download the EE Code for 22 - Displaying Related Events on Ministry Pages

So - at this point I’ve a relationship established between an event and a ministry.  The event detail page is showing a link to “sponsoring ministry”, but I also want the ministry detail pages to show links to “upcoming events”.  From an individual ministry point of view this provides them a nice little mini home page with all the important information someone would want to know.

Adding Events to Ministries Detail
If you look at the updated Crafty Old People ministry page, you’ll see that the left column now has “Upcoming Events”.  These link to the event detail page, and are only the events that are sponsored by the Crafty Old People.

I’ll provide the complete updated template in the companion files below, but in the mean time here is the code that’s pulling those events in.  Give it a once-over then I’ll hit the specifics:

{exp:weblog:entries weblog="ministries" 
disable="trackbacks|member_data|pagination" limit="1"}

<div class="ministry_contact">
h3>Ministry Contact:</h3>

div class="navcontainer">
h3>Upcoming Events</h3>
ul class="navlist">
{reverse_related_entries sort="asc" weblog="events"}
             {if no_reverse_related_entries}
<li>No Events are Scheduled</li>
        {if entry_date 
<li><a href="{url_title_path=events/details}">{title} {entry_date format="%F %d"}</a></li>


So nested in a weblog:entries tag is the reverse_related_entries.  Why reverse_related and not related_entries?

If you remember - the relationship field that ties these two content types together is in the Event weblog.  That makes an event the parent and the ministry is the child.  Since in this code I’m in a weblog:entries tag that is specifying the child (Ministry) weblog, I need to use reverse_related_entries to pull parent (Event) information.

With me?

So it’s the reverse_related_entries tag and within that tag I need to specify the parent (Events) weblog.  Keep in mind that you might have multiple content relationships - so the tag needs to know where to look in this case.  Since I’m dealing with date-related content, I’ve specified a sort such that the next upcoming event is listed first.

Now - it’s a given that not all ministries will have events.  So I’m using the “if no_reverse_related_entries” conditional to look for that case and display a message if so.  You might include a link to “view all other events” here if you want.

Now I have the following code:

{if entry_date current_time} 

What I didn’t want was events that had already passed to show in this list.  This code compares the date of the event to a Standard Global Variable called current_time.  If the entry date is larger (further out) than the current time the event displays.

Honestly, this isn’t ideal.  You’ll see in the next chapter that with the weblog:entries tag there is a better way to limit its results to just the entries in the future.  It’s called the start_on parameter.  However - it’s not available as a parameter on reverse_related_entries.  There is a feature request that you can add your support to if you want.

So what’s this mean?  If a ministry had events, but they’re all in the past, the if_no_results won’t trigger as it’s not looking at date.  The code will then proceed to try and list the events.  The second conditional will evaluate to true for all events, so the result will be an empty list with no “sorry Charlie” message for the user.

One option is to close out past events—as reverse_related_entries will honor status and not pull those.  But that strips history from your site as then those events won’t show on the master calendar.  Taking that approach further you could configure the master events calendar and detail pages to pull entries with either an open or closed status - so closed events would come off the ministry detail pages but still show in other spots on the site.  For my purposes I’m going to leave things as-is - there’s always the hope that EE 2.0 will have extended relationship handling (and for the record—I don’t know!).

In the next chapter I’ll cover pulling events to the home page.  I had intended to include it here - but as part of displaying the event information I’ll need to use a couple of plugins.  I haven’t yet covered plugins in this series so I’ll break that out into its own chapter.

Category Navigation

<< Previous Entry   

Next Entry >>


Previous Comments

Picture of Brian Lokker

by Brian Lokker

Date: Wednesday, September 24th, 2008
Comment: #1


Is it possible with native EE functionality to display events on ministry pages if (as in my case) the different ministries are in different weblogs? Fox example, could the calendar field group include several related entry fields that relate to the different weblogs, and then distribute the events to these different weblogs using conditionals in the calendar template? Or would it be necessary to use something like the Solspace Related Entries plugin to accomplish this?

Mike Boyink

by Mike Boyink (Author)

Date: Wednesday, September 24th, 2008
Comment: #2

Hey Brian -

Yes, you can setup multiple relationship fields and then use conditionals on the calendar template to only display the ones with content.

It’s not a bad approach up to a half dozen or so relationship fields, but after that starts to feel a bit hackish.

From there either the Solspace plugin or the Playa extension would be my next stop.

Picture of Jennifer

by Jennifer

Date: Thursday, July 2nd, 2009
Comment: #3

Do you have any clue on how to nest a related_entries inside a reverse_related_entries?

I can’t seem to get it to work, after long conversations with the EE forum admins.

Mike Boyink

by Mike Boyink (Author)

Date: Thursday, July 2nd, 2009
Comment: #4

Hi Jennifer—

If you are working with the EE support staff you’re already in the best hands possible.

Picture of Richard Cantwell

by Richard Cantwell

Date: Thursday, January 21st, 2010
Comment: #5

Hi Mike,

I’m using EE 2.0 Beta trial. I’m trying to set up a relationship between a news channel and a team channel. I’ve set up both with a rel field in the news channel called ‘nteam’. I’ve added 1 team [T1] and 4 news articles [N1, N2, N3, N4] and associated all news articles to this team.

I want to show the related news articles when a user goes to this team. In this scenario, the team is the child whilst the news articles are the parents (the other way of doing this is to use {related_entities} tag in the news article to show the team this news article is associated with - i’ve verified this and it works but this is not what i want to do?). I’ve set up the following tags in a template group of mine called ‘teams’ and a template within here for individual team information called ‘team’ (you can see this at http://www.icanhost.net/lansdowne/index.php/teams/team/1st) ...

        {exp:channel:entries channel=“team” disable=“comments|trackbacks” limit=“1”}

When i run this i get the following error:

Fatal error: Call to undefined function clone() in [PATH]/icanhost/lansdowne/lticaN9/expressionengine/libraries/Functions.php on line 2951

I’ve been reading through loads of forum threads but can’t find a solution? Can you help?

Thanks in advance Mike!!!!!!!

Mike Boyink

by Mike Boyink (Author)

Date: Thursday, January 21st, 2010
Comment: #6

Hey Richard -

Issues with the Beta of 2.0 really need to be posted in the EE forums - that’s where you’ll get the best help and where the EE developers are watching for ways to improve the beta into a release product.

Picture of Nathan

by Nathan

Date: Sunday, March 21st, 2010
Comment: #7


This was helpful, thanks.
Is it possible to to place the next 5 upcoming events, i was thinking of just showing the title and the dates of the events.



Mike Boyink

by Mike Boyink (Author)

Date: Sunday, March 21st, 2010
Comment: #8

Sure…take a look at the docs on the reverse related entries tag for some clues..;)

Add Your Comment

Commenting is not available in this channel entry.

Unless otherwise stated all content is © Michael Boyink of Train-ee.com & Boyink Interactive. Please don't steal - I've got kids to feed...