]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/template.php
WordPress 3.8
[autoinstalls/wordpress.git] / wp-includes / template.php
index d86a677fb604d66bbc9cd508c1e95f613a9fe963..05f773486c38c7b61b5a689a557120cd705a8d2a 100644 (file)
@@ -26,7 +26,19 @@ function get_query_template( $type, $templates = array() ) {
        if ( empty( $templates ) )
                $templates = array("{$type}.php");
 
        if ( empty( $templates ) )
                $templates = array("{$type}.php");
 
-       return apply_filters( "{$type}_template", locate_template( $templates ) );
+       $template = locate_template( $templates );
+       /**
+        * Filter the path of the queried template by type.
+        *
+        * The dynamic portion of the hook name, $type, refers to the filename
+        * -- minus the extension -- of the file to load. This hook also applies
+        * to various types of files loaded as part of the Template Hierarchy.
+        *
+        * @since 1.5.0
+        *
+        * @param string $template Path to the template. @see locate_template()
+        */
+       return apply_filters( "{$type}_template", $template );
 }
 
 /**
 }
 
 /**
@@ -59,17 +71,38 @@ function get_404_template() {
  * @return string
  */
 function get_archive_template() {
  * @return string
  */
 function get_archive_template() {
-       $post_types = get_query_var( 'post_type' );
+       $post_types = array_filter( (array) get_query_var( 'post_type' ) );
 
        $templates = array();
 
 
        $templates = array();
 
-       foreach ( (array) $post_types as $post_type )
+       if ( count( $post_types ) == 1 ) {
+               $post_type = reset( $post_types );
                $templates[] = "archive-{$post_type}.php";
                $templates[] = "archive-{$post_type}.php";
+       }
        $templates[] = 'archive.php';
 
        return get_query_template( 'archive', $templates );
 }
 
        $templates[] = 'archive.php';
 
        return get_query_template( 'archive', $templates );
 }
 
+/**
+ * Retrieve path of post type archive template in current or parent template.
+ *
+ * @since 3.7.0
+ *
+ * @return string
+ */
+function get_post_type_archive_template() {
+       $post_type = get_query_var( 'post_type' );
+       if ( is_array( $post_type ) )
+               $post_type = reset( $post_type );
+
+       $obj = get_post_type_object( $post_type );
+       if ( ! $obj->has_archive )
+               return '';
+
+       return get_archive_template();
+}
+
 /**
  * Retrieve path of author template in current or parent template.
  *
 /**
  * Retrieve path of author template in current or parent template.
  *
@@ -82,7 +115,7 @@ function get_author_template() {
 
        $templates = array();
 
 
        $templates = array();
 
-       if ( $author ) {
+       if ( is_a( $author, 'WP_User' ) ) {
                $templates[] = "author-{$author->user_nicename}.php";
                $templates[] = "author-{$author->ID}.php";
        }
                $templates[] = "author-{$author->user_nicename}.php";
                $templates[] = "author-{$author->ID}.php";
        }
@@ -94,8 +127,8 @@ function get_author_template() {
 /**
  * Retrieve path of category template in current or parent template.
  *
 /**
  * Retrieve path of category template in current or parent template.
  *
- * Works by first retrieving the current slug for example 'category-default.php' and then
- * trying category ID, for example 'category-1.php' and will finally fallback to category.php
+ * Works by first retrieving the current slug, for example 'category-default.php', and then
+ * trying category ID, for example 'category-1.php', and will finally fall back to category.php
  * template, if those files don't exist.
  *
  * @since 1.5.0
  * template, if those files don't exist.
  *
  * @since 1.5.0
@@ -108,7 +141,7 @@ function get_category_template() {
 
        $templates = array();
 
 
        $templates = array();
 
-       if ( $category ) {
+       if ( ! empty( $category->slug ) ) {
                $templates[] = "category-{$category->slug}.php";
                $templates[] = "category-{$category->term_id}.php";
        }
                $templates[] = "category-{$category->slug}.php";
                $templates[] = "category-{$category->term_id}.php";
        }
@@ -120,8 +153,8 @@ function get_category_template() {
 /**
  * Retrieve path of tag template in current or parent template.
  *
 /**
  * Retrieve path of tag template in current or parent template.
  *
- * Works by first retrieving the current tag name, for example 'tag-wordpress.php' and then
- * trying tag ID, for example 'tag-1.php' and will finally fallback to tag.php
+ * Works by first retrieving the current tag name, for example 'tag-wordpress.php', and then
+ * trying tag ID, for example 'tag-1.php', and will finally fall back to tag.php
  * template, if those files don't exist.
  *
  * @since 2.3.0
  * template, if those files don't exist.
  *
  * @since 2.3.0
@@ -134,7 +167,7 @@ function get_tag_template() {
 
        $templates = array();
 
 
        $templates = array();
 
-       if ( $tag ) {
+       if ( ! empty( $tag->slug ) ) {
                $templates[] = "tag-{$tag->slug}.php";
                $templates[] = "tag-{$tag->term_id}.php";
        }
                $templates[] = "tag-{$tag->slug}.php";
                $templates[] = "tag-{$tag->term_id}.php";
        }
@@ -165,7 +198,7 @@ function get_taxonomy_template() {
 
        $templates = array();
 
 
        $templates = array();
 
-       if ( $term ) {
+       if ( ! empty( $term->slug ) ) {
                $taxonomy = $term->taxonomy;
                $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
                $templates[] = "taxonomy-$taxonomy.php";
                $taxonomy = $term->taxonomy;
                $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
                $templates[] = "taxonomy-$taxonomy.php";
@@ -189,7 +222,7 @@ function get_date_template() {
 /**
  * Retrieve path of home template in current or parent template.
  *
 /**
  * Retrieve path of home template in current or parent template.
  *
- * This is the template used for the page containing the blog posts
+ * This is the template used for the page containing the blog posts.
  *
  * Attempts to locate 'home.php' first before falling back to 'index.php'.
  *
  *
  * Attempts to locate 'home.php' first before falling back to 'index.php'.
  *
@@ -223,9 +256,9 @@ function get_front_page_template() {
 /**
  * Retrieve path of page template in current or parent template.
  *
 /**
  * Retrieve path of page template in current or parent template.
  *
- * Will first look for the specifically assigned page template
- * The will search for 'page-{slug}.php' followed by 'page-id.php'
- * and finally 'page.php'
+ * Will first look for the specifically assigned page template.
+ * Then will search for 'page-{slug}.php', followed by 'page-{id}.php',
+ * and finally 'page.php'.
  *
  * @since 1.5.0
  *
  *
  * @since 1.5.0
  *
@@ -239,7 +272,8 @@ function get_page_template() {
        if ( ! $pagename && $id ) {
                // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
                $post = get_queried_object();
        if ( ! $pagename && $id ) {
                // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
                $post = get_queried_object();
-               $pagename = $post->post_name;
+               if ( $post )
+                       $pagename = $post->post_name;
        }
 
        $templates = array();
        }
 
        $templates = array();
@@ -288,7 +322,7 @@ function get_single_template() {
 
        $templates = array();
 
 
        $templates = array();
 
-       if ( $object )
+       if ( ! empty( $object->post_type ) )
                $templates[] = "single-{$object->post_type}.php";
        $templates[] = "single.php";
 
                $templates[] = "single-{$object->post_type}.php";
        $templates[] = "single.php";
 
@@ -319,10 +353,12 @@ function get_attachment_template() {
                if ( ! empty( $type ) ) {
                        if ( $template = get_query_template( $type[0] ) )
                                return $template;
                if ( ! empty( $type ) ) {
                        if ( $template = get_query_template( $type[0] ) )
                                return $template;
-                       elseif ( $template = get_query_template( $type[1] ) )
-                               return $template;
-                       elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
-                               return $template;
+                       elseif ( ! empty( $type[1] ) ) {
+                               if ( $template = get_query_template( $type[1] ) )
+                                       return $template;
+                               elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
+                                       return $template;
+                       }
                }
        }
 
                }
        }