Getting the Latest Sermon for Display in Your Theme

To display the latest sermon in your theme, you can use the php code below in your template file. This is especially useful for the home page of your site.

<?php // Setting up the Query - see http://codex.wordpress.org/Class_Reference/WP_Query $latest_sermon = new WP_Query(array( 'post_type' => 'wpfc_sermon', 'posts_per_page' => 1, 'post_status' => 'publish', // Do you want to limit it to a specific service type? Use the service type slug to do it: // More info here: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 'wpfc_service_type' => 'sunday-am', // The last three parameters will optimize your query 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false )); if ($latest_sermon->have_posts()) : ?> <?php while ($latest_sermon->have_posts()) : $latest_sermon->the_post(); ?> <?php global $post; ?> <div id="latest_sermon"> <a id="latest_sermon_title" title="<?php echo esc_attr( get_the_title() ); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a> <span class="meta"> <?php wpfc_sermon_meta('bible_passage', '<span class="bible_passage">'.__( 'Bible Text: ', 'sermon-manager'), '</span> | '); wpfc_sermon_date(get_option('date_format')); ?>&nbsp; </span> <?php // this will output the media links ?> <?php wpfc_sermon_files(); ?> </div> <?php endwhile; ?> <?php // reset the $post variable like below: ?> <?php wp_reset_postdata(); ?> <?php endif; ?>
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

Podcast “Page Not Found” Error

This problem has to do with the way WordPress feeds work (or don’t work in this case). You must...

Template Tags

Version 1.5+ Template tags are used within your theme files to display information...

Getting Started with Sermon Manager for WordPress

After installing Sermon Manager from the WordPress Repository, you’ll see a new top level menu...

Troubleshooting Sermon Manager

Better Questions Get Better Answers Every day, Sermon Manager users email us asking us to fix...

Images for Preachers, Sermon Series, and Topics

Version 1.5+ Displaying Images for an Individual Sermon render_sermon_image($size) This allows...