Back compat for bundled themes. Props nacin, SergeyBiryukov, kobenland. fixes #20768
git-svn-id: http://core.svn.wordpress.org/trunk@20983 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
82122d2ba8
commit
55958522c1
|
@ -114,7 +114,7 @@ function twentyeleven_setup() {
|
||||||
add_theme_support( 'post-thumbnails' );
|
add_theme_support( 'post-thumbnails' );
|
||||||
|
|
||||||
// Add support for custom headers.
|
// Add support for custom headers.
|
||||||
add_theme_support( 'custom-header', array(
|
$custom_header_support = array(
|
||||||
// The default header text color.
|
// The default header text color.
|
||||||
'default-text-color' => '000',
|
'default-text-color' => '000',
|
||||||
// The height and width of our custom header.
|
// The height and width of our custom header.
|
||||||
|
@ -130,16 +130,28 @@ function twentyeleven_setup() {
|
||||||
'admin-head-callback' => 'twentyeleven_admin_header_style',
|
'admin-head-callback' => 'twentyeleven_admin_header_style',
|
||||||
// Callback used to display the header preview in the admin.
|
// Callback used to display the header preview in the admin.
|
||||||
'admin-preview-callback' => 'twentyeleven_admin_header_image',
|
'admin-preview-callback' => 'twentyeleven_admin_header_image',
|
||||||
) );
|
);
|
||||||
|
|
||||||
|
add_theme_support( 'custom-header', $custom_header_support );
|
||||||
|
|
||||||
|
if ( ! function_exists( 'get_custom_header' ) ) {
|
||||||
|
// This is all for compatibility with versions of WordPress prior to 3.4.
|
||||||
|
define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
|
||||||
|
define( 'HEADER_IMAGE', '' );
|
||||||
|
define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
|
||||||
|
define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
|
||||||
|
add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
|
||||||
|
add_custom_background();
|
||||||
|
}
|
||||||
|
|
||||||
// We'll be using post thumbnails for custom header images on posts and pages.
|
// We'll be using post thumbnails for custom header images on posts and pages.
|
||||||
// We want them to be the size of the header image that we just defined
|
// We want them to be the size of the header image that we just defined
|
||||||
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
|
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
|
||||||
set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
|
set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
|
||||||
|
|
||||||
// Add Twenty Eleven's custom image sizes.
|
// Add Twenty Eleven's custom image sizes.
|
||||||
// Used for large feature (header) images.
|
// Used for large feature (header) images.
|
||||||
add_image_size( 'large-feature', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
|
add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
|
||||||
// Used for featured posts if a large-feature doesn't exist.
|
// Used for featured posts if a large-feature doesn't exist.
|
||||||
add_image_size( 'small-feature', 500, 300 );
|
add_image_size( 'small-feature', 500, 300 );
|
||||||
|
|
||||||
|
@ -207,8 +219,9 @@ function twentyeleven_header_style() {
|
||||||
$text_color = get_header_textcolor();
|
$text_color = get_header_textcolor();
|
||||||
|
|
||||||
// If no custom options for text are set, let's bail.
|
// If no custom options for text are set, let's bail.
|
||||||
if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
|
if ( $text_color == HEADER_TEXTCOLOR )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If we get this far, we have custom styles. Let's do this.
|
// If we get this far, we have custom styles. Let's do this.
|
||||||
?>
|
?>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
@ -269,7 +282,7 @@ function twentyeleven_admin_header_style() {
|
||||||
}
|
}
|
||||||
<?php
|
<?php
|
||||||
// If the user has set a custom color for the text use that
|
// If the user has set a custom color for the text use that
|
||||||
if ( get_header_textcolor() != get_theme_support( 'custom-header', 'default-text-color' ) ) :
|
if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
|
||||||
?>
|
?>
|
||||||
#site-title a,
|
#site-title a,
|
||||||
#site-description {
|
#site-description {
|
||||||
|
|
|
@ -79,8 +79,15 @@
|
||||||
// Check to see if the header image has been removed
|
// Check to see if the header image has been removed
|
||||||
$header_image = get_header_image();
|
$header_image = get_header_image();
|
||||||
if ( $header_image ) :
|
if ( $header_image ) :
|
||||||
$header_image_width = get_custom_header()->width;
|
// Compatibility with versions of WordPress prior to 3.4.
|
||||||
?>
|
if ( function_exists( 'get_custom_header' ) ) {
|
||||||
|
// We need to figure out what the minimum width should be for our featured image.
|
||||||
|
// This result would be the suggested width if the theme were to implement flexible widths.
|
||||||
|
$header_image_width = get_theme_support( 'custom-header', 'width' );
|
||||||
|
} else {
|
||||||
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
||||||
|
}
|
||||||
|
?>
|
||||||
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
|
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
|
||||||
<?php
|
<?php
|
||||||
// The header image
|
// The header image
|
||||||
|
@ -90,8 +97,17 @@
|
||||||
$image[1] >= $header_image_width ) :
|
$image[1] >= $header_image_width ) :
|
||||||
// Houston, we have a new header image!
|
// Houston, we have a new header image!
|
||||||
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
|
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
|
||||||
else : ?>
|
else :
|
||||||
<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
|
// Compatibility with versions of WordPress prior to 3.4.
|
||||||
|
if ( function_exists( 'get_custom_header' ) ) {
|
||||||
|
$header_image_width = get_custom_header()->width;
|
||||||
|
$header_image_height = get_custom_header()->height;
|
||||||
|
} else {
|
||||||
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
||||||
|
$header_image_height = HEADER_IMAGE_HEIGHT;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
|
||||||
<?php endif; // end check for featured image or standard header ?>
|
<?php endif; // end check for featured image or standard header ?>
|
||||||
</a>
|
</a>
|
||||||
<?php endif; // end check for removed header image ?>
|
<?php endif; // end check for removed header image ?>
|
||||||
|
|
|
@ -66,8 +66,12 @@ get_header(); ?>
|
||||||
*/
|
*/
|
||||||
$counter_slider = 0;
|
$counter_slider = 0;
|
||||||
|
|
||||||
$header_image_width = get_theme_support( 'custom-header', 'width' );
|
// Compatibility with versions of WordPress prior to 3.4.
|
||||||
?>
|
if ( function_exists( 'get_custom_header' ) )
|
||||||
|
$header_image_width = get_theme_support( 'custom-header', 'width' );
|
||||||
|
else
|
||||||
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
||||||
|
?>
|
||||||
|
|
||||||
<div class="featured-posts">
|
<div class="featured-posts">
|
||||||
<h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
|
<h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
|
||||||
|
|
|
@ -101,7 +101,7 @@ function twentyten_setup() {
|
||||||
|
|
||||||
// The custom header business starts here.
|
// The custom header business starts here.
|
||||||
|
|
||||||
add_theme_support( 'custom-header', array(
|
$custom_header_support = array(
|
||||||
// The default image to use.
|
// The default image to use.
|
||||||
// The %s is a placeholder for the theme template directory URI.
|
// The %s is a placeholder for the theme template directory URI.
|
||||||
'default-image' => '%s/images/headers/path.jpg',
|
'default-image' => '%s/images/headers/path.jpg',
|
||||||
|
@ -114,12 +114,25 @@ function twentyten_setup() {
|
||||||
'header-text' => false,
|
'header-text' => false,
|
||||||
// Callback for styling the header preview in the admin.
|
// Callback for styling the header preview in the admin.
|
||||||
'admin-head-callback' => 'twentyten_admin_header_style',
|
'admin-head-callback' => 'twentyten_admin_header_style',
|
||||||
) );
|
);
|
||||||
|
|
||||||
|
add_theme_support( 'custom-header', $custom_header_support );
|
||||||
|
|
||||||
|
if ( ! function_exists( 'get_custom_header' ) ) {
|
||||||
|
// This is all for compatibility with versions of WordPress prior to 3.4.
|
||||||
|
define( 'HEADER_TEXTCOLOR', '' );
|
||||||
|
define( 'NO_HEADER_TEXT', true );
|
||||||
|
define( 'HEADER_IMAGE', $custom_header_support['default-image'] );
|
||||||
|
define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
|
||||||
|
define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
|
||||||
|
add_custom_image_header( '', $custom_header_support['admin-head-callback'] );
|
||||||
|
add_custom_background();
|
||||||
|
}
|
||||||
|
|
||||||
// We'll be using post thumbnails for custom header images on posts and pages.
|
// We'll be using post thumbnails for custom header images on posts and pages.
|
||||||
// We want them to be 940 pixels wide by 198 pixels tall.
|
// We want them to be 940 pixels wide by 198 pixels tall.
|
||||||
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
|
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
|
||||||
set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
|
set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
|
||||||
|
|
||||||
// ... and thus ends the custom header business.
|
// ... and thus ends the custom header business.
|
||||||
|
|
||||||
|
|
|
@ -66,22 +66,33 @@
|
||||||
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
|
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
// Compatibility with versions of WordPress prior to 3.4.
|
||||||
|
if ( function_exists( 'get_custom_header' ) ) {
|
||||||
|
// We need to figure out what the minimum width should be for our featured image.
|
||||||
|
// This result would be the suggested width if the theme were to implement flexible widths.
|
||||||
|
$header_image_width = get_theme_support( 'custom-header', 'width' );
|
||||||
|
} else {
|
||||||
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
|
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
|
||||||
if ( is_singular() && current_theme_supports( 'post-thumbnails' ) &&
|
if ( is_singular() && current_theme_supports( 'post-thumbnails' ) &&
|
||||||
has_post_thumbnail( $post->ID ) &&
|
has_post_thumbnail( $post->ID ) &&
|
||||||
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
|
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
|
||||||
$image[1] >= get_theme_support( 'custom-header', 'width' ) ) :
|
$image[1] >= $header_image_width ) :
|
||||||
// Houston, we have a new header image!
|
// Houston, we have a new header image!
|
||||||
echo get_the_post_thumbnail( $post->ID );
|
echo get_the_post_thumbnail( $post->ID );
|
||||||
elseif ( get_header_image() ) :
|
elseif ( get_header_image() ) :
|
||||||
|
// Compatibility with versions of WordPress prior to 3.4.
|
||||||
if ( function_exists( 'get_custom_header' ) ) {
|
if ( function_exists( 'get_custom_header' ) ) {
|
||||||
$header_width = get_custom_header()->width;
|
$header_image_width = get_custom_header()->width;
|
||||||
$header_height = get_custom_header()->height;
|
$header_image_height = get_custom_header()->height;
|
||||||
} else {
|
} else {
|
||||||
$header_height = $header_width = '';
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
||||||
|
$header_image_height = HEADER_IMAGE_HEIGHT;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<img src="<?php header_image(); ?>" width="<?php echo $header_width; ?>" height="<?php echo $header_height; ?>" alt="" />
|
<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div><!-- #branding -->
|
</div><!-- #branding -->
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue