Look for single-.php templates. Add single- class to get_body_class(). Props ptahdunbar. see #12105
git-svn-id: https://develop.svn.wordpress.org/trunk@13032 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b3d7aae458
commit
712c98007d
@ -392,14 +392,17 @@ function get_body_class( $class = '' ) {
|
|||||||
$classes[] = 'error404';
|
$classes[] = 'error404';
|
||||||
|
|
||||||
if ( is_single() ) {
|
if ( is_single() ) {
|
||||||
$postID = $wp_query->get_queried_object_id();
|
$post_id = $wp_query->get_queried_object_id();
|
||||||
|
$post = $wp_query->get_queried_object();
|
||||||
|
|
||||||
$classes[] = 'single postid-' . $postID;
|
$classes[] = 'single';
|
||||||
|
$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
|
||||||
|
$classes[] = 'postid-' . $post_id;
|
||||||
|
|
||||||
if ( is_attachment() ) {
|
if ( is_attachment() ) {
|
||||||
$mime_type = get_post_mime_type($postID);
|
$mime_type = get_post_mime_type($post_id);
|
||||||
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
|
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
|
||||||
$classes[] = 'attachmentid-' . $postID;
|
$classes[] = 'attachmentid-' . $post_id;
|
||||||
$classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
|
$classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
|
||||||
}
|
}
|
||||||
} elseif ( is_archive() ) {
|
} elseif ( is_archive() ) {
|
||||||
@ -419,13 +422,13 @@ function get_body_class( $class = '' ) {
|
|||||||
} elseif ( is_page() ) {
|
} elseif ( is_page() ) {
|
||||||
$classes[] = 'page';
|
$classes[] = 'page';
|
||||||
|
|
||||||
$pageID = $wp_query->get_queried_object_id();
|
$page_id = $wp_query->get_queried_object_id();
|
||||||
|
|
||||||
$post = get_page($pageID);
|
$post = get_page($page_id);
|
||||||
|
|
||||||
$classes[] = 'page-id-' . $pageID;
|
$classes[] = 'page-id-' . $page_id;
|
||||||
|
|
||||||
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) ) )
|
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) ) )
|
||||||
$classes[] = 'page-parent';
|
$classes[] = 'page-parent';
|
||||||
|
|
||||||
if ( $post->post_parent ) {
|
if ( $post->post_parent ) {
|
||||||
@ -434,7 +437,7 @@ function get_body_class( $class = '' ) {
|
|||||||
}
|
}
|
||||||
if ( is_page_template() ) {
|
if ( is_page_template() ) {
|
||||||
$classes[] = 'page-template';
|
$classes[] = 'page-template';
|
||||||
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $pageID, '_wp_page_template', true ) ), '' );
|
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
|
||||||
}
|
}
|
||||||
} elseif ( is_search() ) {
|
} elseif ( is_search() ) {
|
||||||
if ( !empty($wp_query->posts) )
|
if ( !empty($wp_query->posts) )
|
||||||
|
@ -2549,9 +2549,8 @@ class WP_Query {
|
|||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
function get_queried_object() {
|
function get_queried_object() {
|
||||||
if (isset($this->queried_object)) {
|
if ( isset($this->queried_object) )
|
||||||
return $this->queried_object;
|
return $this->queried_object;
|
||||||
}
|
|
||||||
|
|
||||||
$this->queried_object = NULL;
|
$this->queried_object = NULL;
|
||||||
$this->queried_object_id = 0;
|
$this->queried_object_id = 0;
|
||||||
|
@ -860,7 +860,7 @@ function get_home_template() {
|
|||||||
function get_page_template() {
|
function get_page_template() {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
|
||||||
$id = (int) $wp_query->post->ID;
|
$id = (int) $wp_query->get_queried_object_id();
|
||||||
$template = get_post_meta($id, '_wp_page_template', true);
|
$template = get_post_meta($id, '_wp_page_template', true);
|
||||||
$pagename = get_query_var('pagename');
|
$pagename = get_query_var('pagename');
|
||||||
|
|
||||||
@ -909,7 +909,11 @@ function get_search_template() {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_single_template() {
|
function get_single_template() {
|
||||||
return get_query_template('single');
|
global $wp_query;
|
||||||
|
|
||||||
|
$object = $wp_query->get_queried_object();
|
||||||
|
$templates = array('single-' . $object->post_type . '.php', 'single.php');
|
||||||
|
return apply_filters('single_template', locate_template($templates));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user