Make WordPress Core

Changeset 13032


Ignore:
Timestamp:
02/08/2010 10:05:05 PM (15 years ago)
Author:
ryan
Message:

Look for single-.php templates. Add single- class to get_body_class(). Props ptahdunbar. see #12105

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r13025 r13032  
    393393
    394394    if ( is_single() ) {
    395         $postID = $wp_query->get_queried_object_id();
    396 
    397         $classes[] = 'single postid-' . $postID;
     395        $post_id = $wp_query->get_queried_object_id();
     396        $post = $wp_query->get_queried_object();
     397
     398        $classes[] = 'single';
     399        $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
     400        $classes[] = 'postid-' . $post_id;
    398401
    399402        if ( is_attachment() ) {
    400             $mime_type = get_post_mime_type($postID);
     403            $mime_type = get_post_mime_type($post_id);
    401404            $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
    402             $classes[] = 'attachmentid-' . $postID;
     405            $classes[] = 'attachmentid-' . $post_id;
    403406            $classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
    404407        }
     
    420423        $classes[] = 'page';
    421424
    422         $pageID = $wp_query->get_queried_object_id();
    423 
    424         $post = get_page($pageID);
    425 
    426         $classes[] = 'page-id-' . $pageID;
    427 
    428         if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $pageID) ) )
     425        $page_id = $wp_query->get_queried_object_id();
     426
     427        $post = get_page($page_id);
     428
     429        $classes[] = 'page-id-' . $page_id;
     430
     431        if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) )
    429432            $classes[] = 'page-parent';
    430433
     
    435438        if ( is_page_template() ) {
    436439            $classes[] = 'page-template';
    437             $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $pageID, '_wp_page_template', true ) ), '' );
     440            $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
    438441        }
    439442    } elseif ( is_search() ) {
  • trunk/wp-includes/query.php

    r12995 r13032  
    25502550     */
    25512551    function get_queried_object() {
    2552         if (isset($this->queried_object)) {
     2552        if ( isset($this->queried_object) )
    25532553            return $this->queried_object;
    2554         }
    25552554
    25562555        $this->queried_object = NULL;
    25572556        $this->queried_object_id = 0;
    25582557
    2559         if ($this->is_category) {
     2558        if ( $this->is_category ) {
    25602559            $cat = $this->get('cat');
    25612560            $category = &get_category($cat);
     
    25642563            $this->queried_object = &$category;
    25652564            $this->queried_object_id = (int) $cat;
    2566         } else if ($this->is_tag) {
     2565        } elseif ( $this->is_tag ) {
    25672566            $tag_id = $this->get('tag_id');
    25682567            $tag = &get_term($tag_id, 'post_tag');
     
    25712570            $this->queried_object = &$tag;
    25722571            $this->queried_object_id = (int) $tag_id;
    2573         } else if ($this->is_tax) {
     2572        } elseif ( $this->is_tax ) {
    25742573            $tax = $this->get('taxonomy');
    25752574            $slug = $this->get('term');
     
    25802579            $this->queried_object = $term;
    25812580            $this->queried_object_id = $term->term_id;
    2582         } else if ($this->is_posts_page) {
     2581        } elseif ( $this->is_posts_page ) {
    25832582            $this->queried_object = & get_page(get_option('page_for_posts'));
    25842583            $this->queried_object_id = (int) $this->queried_object->ID;
    2585         } else if ($this->is_single) {
     2584        } elseif ( $this->is_single ) {
    25862585            $this->queried_object = $this->post;
    25872586            $this->queried_object_id = (int) $this->post->ID;
    2588         } else if ($this->is_page) {
     2587        } elseif ( $this->is_page ) {
    25892588            $this->queried_object = $this->post;
    25902589            $this->queried_object_id = (int) $this->post->ID;
    2591         } else if ($this->is_author) {
     2590        } elseif ( $this->is_author ) {
    25922591            $author_id = (int) $this->get('author');
    25932592            $author = get_userdata($author_id);
  • trunk/wp-includes/theme.php

    r13020 r13032  
    861861    global $wp_query;
    862862
    863     $id = (int) $wp_query->post->ID;
     863    $id = (int) $wp_query->get_queried_object_id();
    864864    $template = get_post_meta($id, '_wp_page_template', true);
    865865    $pagename = get_query_var('pagename');
     
    910910 */
    911911function get_single_template() {
    912     return get_query_template('single');
     912    global $wp_query;
     913
     914    $object = $wp_query->get_queried_object();
     915    $templates = array('single-' . $object->post_type . '.php', 'single.php');
     916    return apply_filters('single_template', locate_template($templates));
    913917}
    914918
     
    975979 */
    976980function locate_template($template_names, $load = false) {
    977     if (!is_array($template_names))
     981    if ( !is_array($template_names) )
    978982        return '';
    979983
    980984    $located = '';
    981     foreach($template_names as $template_name) {
     985    foreach ( $template_names as $template_name ) {
    982986        if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    983987            $located = STYLESHEETPATH . '/' . $template_name;
     
    989993    }
    990994
    991     if ($load && '' != $located)
     995    if ( $load && '' != $located )
    992996        load_template($located);
    993997
Note: See TracChangeset for help on using the changeset viewer.