taxonomy ) ? str_replace( 'post-format-', '', $term->slug ) : $term->slug ); // Return the available templates return locate_template( array( "taxonomy-{$term->taxonomy}-{$slug}.php", "taxonomy-{$term->taxonomy}.php", 'taxonomy.php', 'archive.php' ) ); } /** * Overrides the default single (singular post) template. Post templates can be loaded using a custom * post template, by slug, or by ID. * * Attachment templates are handled slightly differently. Rather than look for the slug * or ID, templates can be loaded by attachment-$mime[0]_$mime[1].php, * attachment-$mime[1].php, or attachment-$mime[0].php. */ function spyropress_singular_template( $template ) { $templates = array(); // Get the queried post $post = get_queried_object(); // Check for a custom post template by custom field key '_wp_post_template' $custom = get_post_meta( get_queried_object_id(), "_wp_{$post->post_type}_template", true ); if ( $custom ) $templates[] = $custom; // If viewing an attachment page, handle the files by mime type if ( is_attachment() ) { // Split the mime_type into two distinct parts $type = explode( '/', get_post_mime_type() ); $templates[] = "attachment-{$type[0]}_{$type[1]}.php"; $templates[] = "attachment-{$type[1]}.php"; $templates[] = "attachment-{$type[0]}.php"; } // If viewing any other type of singular page else { // Add a post name (slug) template $templates[] = "{$post->post_type}-{$post->post_name}.php"; // Add a post ID template $templates[] = "{$post->post_type}-{$post->ID}.php"; } // Add a template based off the post type name $templates[] = "{$post->post_type}.php"; // Allow for WP standard 'single' templates for compatibility $templates[] = "single-{$post->post_type}.php"; // Add a general template of singular.php $templates[] = "singular.php"; $templates[] = 'single.php'; // Return the found template return locate_template( $templates ); } ?>