Images for Preachers, Sermon Series, and Topics

Version 1.5+

Displaying Images for an Individual Sermon

This allows you to display the sermon image in the size of your choice. Any size registered with add_image_size can be displayed. First, this function checks to see if a featured image is set for the sermon. If so, it is displayed. If not, it looks for an associated with the sermon series. If one isn’t assigned it will display the speaker’s image. If none of those are set, nothing will be displayed.
To use the thumbnail size: <?php render_sermon_image('thumbnail'); ?>

Displaying Your Images in Your Theme

There are a few filters that you can use in your theme to display the image associations created by this plugin. Please read below for detailed information.

Display a single image representing the term archive

The following filter will display the image associated with the term asked for in the query string of the url. This filter only works in views that naturally use templates like category.php, tag.php taxonomy.php and all of their derivatives. Please read about template hierarchy for more information about these templates. The simplest use of this filter looks like:

This code will generate and print an image tag. It’s output can be modifed by passig an optional third parameter to apply filters. This parameter is an array and the following keys may be set:

  • after (string) – Text to append to the image’s HTML.
  • attr (array) – Key/value pairs representing the attributes of the img tag. Available options include: alt, class, src and title. This array will be passed as the fourth parameter to WordPress core function wp_get_attachment_image() without modification.
  • before (string) – Text to prepend to the image’s HTML.
  • image_size (string) – May be any image size registered with WordPress. If no image size is specified, ‘thumbnail’ will be used as a default value. In the event that an unregistered size is specified, this filter will return an empty string.

Here’s an example of what a fully customized version of this filter might look like:

Similar functionality

If you just need to get the database ID for the image, you may want to use:

If you need to get the full object of the image, you may want to use:

If you need to get the url to the image, you may want to use the following:

You can specify the size of the image in an option third parameter:

If you need data about the image, you may want to use:

You can specify the size of the image in an option third parameter:

List term images associated with a sermon

When a sermon is being displayed you may want to display all of the images associated with all of the terms that are associated with the sermon (a mouthful? Yes indeed!). The sermon-images-list-the-terms filter does this. Here’s what it looks like in its simplest form:

This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:

  • after (string) – Text to append to the output. Default value is a closing unordered list element.
  • after_image (string) – Text to append to each image. Default value is a closing list-item element.
  • before (string) – Text to prepend to the output. Default value is an open unordered list element with an class attribute of “sermon-images-the-terms”.
  • before_image (string) – Text to prepend to each image. Default value is an open list-item element.
  • image_size (string) – Any registered image size. Values will vary from installation to installation. Image sizes defined in core include: “thumbnail”, “medium” and “large”. “Fullsize” may also be used to get the unmodified image that was uploaded. Defaults to “thumbnail”.
  • post_id (int) – The post to retrieve terms from. Defaults to the ID property of the global $post object.
  • taxonomy (string) – Name of a registered taxonomy to return terms from. For example,  “wpfc_preacher”, “wpfc_sermon_series”, or “wpfc_sermon_topics”.

Here’s an example of what a fully customized version of this filter might look like:

Working with all terms of a given taxonomy

You will want to use the ‘sermon-images-get-terms’ filter. This filter is basically a wrapper for WordPress core function get_terms(). It will return an array of enhanced term objects: each term object will have a custom property named image_id which is an integer representing the database ID of the image associated with the term. This filter can be used to create custom lists of terms. Here’s what it’s default useage looks like:

Here is what php’s print_r() function may return:

As you can see, all of the goodness of get_terms() is there with an added bonus: the image_id parameter!

This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:

  • cache_images (bool) If this value is true all associated images will be queried for and cached for later use in various template tags. If it is set to false, this query will be suppressed. Do not set this value to false unless you have a really good reason for doing so :) Default value is true.
  • having_images (bool) If this value is true then only terms that have associated images will be returned. Setting it to false will return all terms. Default value is true.
  • taxonomy (string) Name of a registered taxonomy to return terms from. Multiple taxonomies may be specified by separating each name by a comma. Defaults to “category”.
  • term_args (array) Arguments to pass to get_terms() as the second parameter. Default value is an empty array.

Here’s and example of a simple custom loop that you can make to display all term images:

Code and Documentation adapted from Michael Fields’ excellent plugin: http://wordpress.org/extend/plugins/taxonomy-images/