Testing for Post Type Archives

The Custom Post Types plugin provides the function is_post_type_archive() which allows me to check if I’m on an archive page for a custom post type.

By using this, I can load different sidebars depending on whether I’m viewing custom post types or normal blog posts. The sermon post type is displayed with sermon-template.php, has views by taxonomy and also chronological archives. To cover these cases, the current code is

if(is_post_type_archive('sermon') || is_tax() || is_page_template('sermon-template.php'))

The is_tax() function will probably have to be made more specific when new post types and taxonomies are added. This line is placed in my own version of sidebar.php, which will override the default. The idea is to show the primary widget area for sermon types, and the secondary sidebar for other things. The widgets will be arranged so that this makes sense.

Advertisements

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