17 - Implementing the Worship Section
In this chapter I’ll cover the ExpressionEngine implementation of the Worship section of the example church site. From a content perspective, the Worship content will live in one place and be displayed on both the Worship page and the site’s home page. From an EE perspective, the build approach will cover nesting two EE tags to accomplish the content formatting required.
A Bit of a Direction Change
I’ve decided to implement this section of the site a bit differently than I laid out in the ExpressionEngine Architecture chapter.
It seemed like the basic information around a specific worship event should be able to be communicated right on the index page, without requiring any further navigation. The page only needs an overview statement about the Worship content, and then just the weekdays and times for the different worship events. Making that decision simplified the requirements both in the number of custom fields and templates required.
I did allow for a photo or graphic for each Worship event as I have often seen churches do a bit of branding work to help identify the nature of different worship services - be they traditional or contemporary, etc.
I will note - if your needs are such that each worship event should have its own detail page (much like how the Ministries section was implemented) it’s just a matter of at least one more custom field and one more template. You can follow the Ministries section as a rough guide for how to add that deeper layer of navigation.
A Preview
If you want to take a look at the completed Worship section before reading through how it was created - you can visit the live page here.
Overall Approach
For my approach the overall steps to implementation are:
- Create a Worship template group
- Copy page_comps/one-column-content as a starting point
- Create a Worship weblog
- Create a Worship field group and Add Fields
- Create a Worship category group and Add Categories
- Create a Worship file upload destination
- Publish content
- Edit worship/index to pull in content
- Edit site/index to pull content from Worship weblog
Create a Worship Template Group
I’ve covered the specific steps of creating template groups in past chapters so I’ll gloss over this a bit here. You just need to come out with a template group named “worship”, and have its index template be a copy of page_comps/one-column-content.
Create a Worship Weblog
Again, at this point in the tutorial, you will have created a few weblogs. Create another one named “Worship”, and don’t choose to create anything else.
Create a Worship Field Group & Add Fields
Create a field group named “Worship” and add the following fields. For each field I’ve listed the Field Name, Field Label, Field Type, Maxlength, Default Formatting, and Searchable settings.
- worship_image, Worship Image, Text Input, 128, None, No
- worship_description, Worship Description, Textarea, 12 Rows, Xhtml, Yes
You might notice I don’t have a specific field for the time of the event. When I looked at how the content would be used it looked like the name of the event and the time would always appear together, so I’m structuring it such that the name and time are always in the title field—so a title would be “Bible Study - 10:30 am”, etc. You can break that up if you want, you’ll just need another custom field to hold the content and will need to specify it in the code.
Create a Category Group and Add Categories
I plan to use categories to hold the days - so for the example site, Sunday and Wednesday will be categories and I’ll use some category-related EE code to get the different Worship events to appear under the days of the week they occur on.
So create a category group called “Worship”, and then two categories within the group. One for “Sunday” and one for “Wednesday”. No category descriptions will be needed.
Connect the Dots
Make sure to connect the new weblog with the new field group and category groups. You can verify this by clicking “Publish” , choosing the new “Worship” weblog, and ensuring that all the fields and categories appear.
Create a New File Upload Destination
This section will have images or photos associated with it so it’s best to create a new directory on your webserver to hold them (use FTP for that, make sure the folder has read/write/execute permissions) and then create a new File Upload Destination like you did for the Ministries section of the site.
Publish Content
Formatting the template will be easier if you have some content to work with - I went ahead and published an entry for each of the Worship entries indicated by the home page content of the sample site, so 6 entries total with 3 on Sunday and 3 on Wednesday. Then I added an entry called “Worship Overview” that will provide the content at the top of the Worship page. This one I did not assign to a category (and that’s crucial, don’t miss it!)
Editing worship/index to Pull Content
I’ll provide a complete template at the bottom as usual, for now I’ll go through the meat of the code that pulls and displays the Worship entries:
<!--BEGIN CONTENT SECTION-->
<div class="interiorBox">
<h2>Worship</h2>
{exp:weblog:entries weblog="worship" disable="trackbacks|member_data|pagination"
url_title="worship-overview" dynamic="off"}
{worship_description}
<br /><br />
{/exp:weblog:entries}
{exp:weblog:category_archive weblog="worship" style="linear"}
{categories}
<h2>{category_name}</h2>
{exp:weblog:entries weblog="worship" category="{category_id}" sort="desc"
disable="member_data|trackbacks|pagination" dynamic="off"}
<img class="worship_image" src="{worship_image}" alt="{title}" />
<h3>{title}</h3>
{worship_description}
<div style="clear:right;"></div>
{/exp:weblog:entries}
<br /><br />
{/categories}
{/exp:weblog:category_archive}
</div><!--END CONTENT SECTION-->
Let’s walk through this.
The first EE tag is pretty straightforward - just a simple weblog:entries set to only pull the Worship Overview entry. Note that I use url_title to grab the specific entry. I could also use entry_id - but prefer url_title, for if the post should happen to get deleted and recreated, there is at least a chance the code will hook up and work again. With entry_id it’s guaranteed to not work, as the new entry would have a new ID (they aren’t re—used in EE).
With that out of the way, things get more interesting. I’ve used a combination of tags - you’ll note that there is a weblog:entries tag nested inside of a category_archive tag.
Why?
Because I want the page content to be formatted first by category, then with entire entries showing under the category name. Neither the category_archive tag or the weblog categories tag allow for this type of output.
So instead the category_archive tag is used to loop through the categories, then for a specific category the ID is passed into the weblog:entries tag as a parameter. Now within the weblog:entries tag I have all the fields available to me, not just the title & url_title.
This might not work if you have many categories and many entries, but for the purposes here it performs just fine—and down the road I can look at caching the page for even better performance.
Oh - also note that the reason the Worship Overview post doesn’t appear in the second chunk of code is that it’s not assigned to a category.
The Results
Here is my completed Worship page:
http://church.train-ee.com/index.php/worship/
Edit site/index to pull content from Worship weblog
With the main Worship section implemented, now I want to look again at the site home page where it also lists the different Worship times. When a new worship event is added or the time changes for an existing one, I don’t want to have to update two places in EE.
In this case, however, I only want the category names and entry titles - so at first glance it seems like a perfect fit for the Category Archive tag. The obstacle to that approach is the way the HTML is structured with the bolded day name and then the events all in that day being wrapped in paragraph tags. Without the paragraph tags the line-heights aren’t right and the content looks goofy. Getting the paragraph tags in using the Category Archive is tough because you’d need to open it within the category pair and close it within the entries pair, and the tag lacks the count and total results variables that would allow the closing paragraph tag to only be generated after the last item in the entry pair.
So - the choices were to re-work the css or choose a different EE approach.
I chose to use the same basic idea as I used on the Worship page - and nest a weblog:entries loop inside a category_archive loop:
<div class="join_us_column">
{exp:weblog:category_archive weblog="worship" style="linear"}
{categories}
<p><b>{category_name}</b><br />
{exp:weblog:entries weblog="worship" category="{category_id}" sort="desc"
disable="member_data|trackbacks|pagination" dynamic="off"}
{title}<br />
{if count==total_results}
</p>
{/if}
{/exp:weblog:entries}
{/categories}
{/exp:weblog:category_archive}
</div>
This gives me access to the count and total results variables so I can determine when to close the paragraph tag.
So There You Have It
A Worship section, with an overview paragraph and entries per worship event with each event having a text description and image. Content is maintained in one place and displayed in two. I’ll come back to this page once the podcasts are in place, and will show how to display the 2 or 3 most recent podcasts from the relevant events.
Next up is the Beliefs section, which should be pretty straightforward.
Category Navigation







by .(JavaScript must be enabled to view this email address)
Date: Friday, July 11th, 2008
Comment: #1
Mike,
Is it your perception that the data in this weblog is relatively static? That is, a one-time setup that works until those recurring events change? Or do you envision a church staff creating entries that are timely for the specific weeks ahead, such that holy day observations and feasts (of the saints) for which the Eucharist is celebrated are input here (and, I presume, also in the Events Calendar). I am trying to imagine this latter case. You could set up an entry that does not expire for the standard services, and set up expiring entries for those like Maundy Thursday or Christmas (which falls each year on a different day/category). The next year you could search for that expired entry, I presume, and edit it to get the right day/category. Is that what you are imagining?
And are you assuming here an acceptable redundancy between the events calendar and worship events, or do you see a clear line that determines what qualifies something for either weblog.