roles ) ) { foreach ( $user->roles as $role ) $templates[] = "user-role-{$role}.php"; } /* Add a basic user template. */ $templates[] = 'user.php'; /* Add backwards compatibility with the WordPress author template. */ $templates[] = 'author.php'; /* Fall back to the basic archive template. */ $templates[] = 'archive.php'; /* Return the found template. */ return locate_template( $templates ); } /** * Overrides WP's default template for category- and tag-based archives. This allows better * organization of taxonomy template files by making categories and post tags work the same way as * other taxonomies. The hierarchy is taxonomy-$taxonomy-$term.php, taxonomy-$taxonomy.php, * taxonomy.php, archive.php. * * @since 0.7.0 * @uses locate_template() Checks for template in child and parent theme. * @param string $template * @return string Full path to file. */ function Easy_taxonomy_template( $template ) { global $wp_query; /* Get the queried term object. */ $term = $wp_query->get_queried_object(); /* Return the available templates. */ return locate_template( array( "taxonomy-{$term->taxonomy}-{$term->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. * * @since 0.7.0 * @param string $template The default WordPress post template. * @return string $template The theme post template after all templates have been checked for. */ function Easy_singular_template( $template ) { global $wp_query; $templates = array(); /* Check for a custom post template by custom field key '_wp_post_template'. */ $custom = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->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[] = "{$wp_query->post->post_type}-{$wp_query->post->post_name}.php"; /* Add a post ID template. */ $templates[] = "{$wp_query->post->post_type}-{$wp_query->post->ID}.php"; } /* Add a template based off the post type name. */ $templates[] = "{$wp_query->post->post_type}.php"; /* Add a general template of singular.php. */ $templates[] = "singular.php"; /* Return the found template. */ return locate_template( $templates ); } ?>