33 - Pulling Audio Messages to Worship Services

This chapter ties up a loose end on with the site’s implementation of audio messages.  I want the Worship section to display, for each worship event, the last few messages that were recorded at it.  I’ve already created the relationship field in the audio-messages field group, now I can use ExpressionEngine’s reverse related entries tag to display them.

Download the EE Code for 33 - Pulling Audio Messages to Worship Services

This chapter won’t take long because all the pieces are there, and I just need to update some code in the worship/index template and add some styles to the stylesheet.

If you recall, when I began the audio messages / podcast implementation in Chapter 28 I created a relationship field in the audio-messages field group.  This field allows the selection of the Worship service where the audio message was recorded.  The intent was to use this content relationship to be able to display, for each service on the Worship page, the 5 most recent audio messages recorded at that service.

I want to do this for a couple of reasons - the first being one of visibility on the site.  The “Audio Messages” link is not in the main navigation instead being shown in the upper right utility nav.  I’m concerned that it will be less findable there so this connection will give users another route to that content. 

The other reason is for newcomers.  If you hadn’t attended this church before and were checking out the worship page to see if the way this church worshiped suited your style and needs, being able to link over and hear the audio from that service would be a great way to get a better feel for it.  Churches often have different services with different styles, and the style & content of the message changes to suit.  Getting some sample messages there along with a picture and some descriptive text will do a fine job of setting their expectations correctly.

I only need do two things to connect the dots here:

  • Add a reverse related entries tag pair to the main weblog entries tag on the worship/index template
  • Update the stylesheet with a couple of new styles for the list of message audio titles

Updating Worship/Index
I’ll provide the entire template in the companion files, so will just focus on the core of the changes here:

{reverse_related_entries weblog="audio-messages" limit="5"}
    {if count
<div class="worship_recent_messages">
b>Audio of Recent Messages</b>
<li><a href="{url_title_path='audio-messages/comments'}">{title}</a></li>
{if count==total_results}

For the most part this is a straightforward use of the reverse related entries tag.  I’ve specified the audio-messages weblog and limit of 5 entries as parameters on the tag.  This code goes in between the opening and closing weblog:entries tag pair already in that template.

However, I only wanted to create the div and unordered list if there were, in fact, audio messages for the Worship being returned.  While reverse_related_entries has the if no_reverse_related_entries conditional, that conditional is geared to be used to display a message if aren’t any related entries.  I just want to not display anything at all, so instead used two conditionals within the reverse related entries loop.  These two conditionals use the count and total_results variables that exist, but seem to be missing from the reverse_related_entries documentation (I found them just by experimenting on a client site).

The first conditional looks for count to equal 1, which should only happen if there are related entries and only the first time looping through if there are more than one.  In this conditional the div and unordered list is opened, and the title is brought in.

A note on the link - I could have brought in all the custom fields from audio-messages here - including the download link for the mp3, wimpy player, etc.  Since there are a number of ways to hear the audio file, and since I’m offering commenting on the file, I choose instead to just link to the single-entry view for the related audio message instead.

After the link is brought in I use a second conditional where count is compared to total results.  This should only happen when the last related entry is returned.  In this conditional the unordered list and div are closed.

This two-conditional approach is great for situations like this where you just don’t want to display anything if there are no related entries.

Stylesheet Changes
I added a couple of entries in the stylesheet mainly for spacing.  I won’t cover them here as you can find the updated stylesheet in the companion files as well.

The Results
The results can be viewed on the Worship Page of the site.

That’s pretty much it!  I may also choose to bring the latest audio message to the site’s home page—which is due for another round of updates at some point anyway.

Category Navigation

<< Previous Entry   

Next Entry >>


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...