Displaying Sermons

The previous post gave links to resources which explained how to create custom post types and taxonomies. After creating them, the next problem is how to display them. It turns out that there is no ridiculously easy way to do so. Some editing of template files is required.

Create New Files

I created a new file named sermon-template.php. The file I used for a starting point was index.php from the original Twenty Ten theme.

The other new file I needed was copied from loop.php and is named loop-sermons.php.

Edit sermon-template.php

Two things have to be done in this file. The WordPress query must be modified with the query_posts() function, and get_template_part() must refer to the new loop file.

query_posts(array('post_type'=>'sermon','posts_per_page'=>2,'paged'=>get_query_var('paged')));
get_template_part('loop','sermons');

This modifies the loop to get all posts of the “sermon” type, to display 2 posts per page, and to show the posts which would have appeared on page x, where x is the number in the URL.

The second line loads loop-sermons.php, where the modified loop will run.

Edit the Loop

I first got rid of all the if-else statements that checked for gallery and asides. The only change I wanted to make was to display the speaker in the post.

echo get_the_term_list(get_the_ID(), 'speaker', "Speaker: ");

This line will get print the text “Speaker: “, followed by the speaker name selected when creating the sermon. The name is actually a link which will show all sermons from that speaker when clicked on. Right now, it uses the archive template to display the sermons belonging to a speaker. This will be modified at a later date.

Advertisements

One thought on “Displaying Sermons”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s