将代码更改为:
<div id=\'xpro_shell_text\' >
<?php
if ( has_post_thumbnail( $post->ID ) ) :
$imageInfo = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'single-post-thumbnail\' );
$imageUrl = $imageInfo[0];
else:
$imageUrl = get_template_directory() . \'PATH TO YOUR DEFAULT IMAGE\';
endif;
?>
<div id="xpro_shell_content_header" class=\'content_about_us_header white\' style="background:url(\'<?php echo $imageUrl; ?>\') no-repeat;">
<div id=\'xpro_shell_content_header_blurb\'>
<h1 class=\'greenHeader cufon_reg\'>
<?php the_title(); ?>
</h1>
<p>
<?php
$message=get_post_meta($post->ID, "myBlurb", true);
if ( get_post_meta($post->ID, "myBlurb", true) ) {
echo ($message);
}
?>
</p>
</div>
</div>
<!--end xpro_shell_content_wrapper_top -->
</div>
UPDATE
诀窍在于:
// If we have a featured image, it will be used as background image using the same logic you already used, but we put the src value in a specific variable: $imageUrl
if ( has_post_thumbnail( $post->ID ) ) :
$imageInfo = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'single-post-thumbnail\' );
$imageUrl = $imageInfo[0];
// if not, we define $imageUrl with our default image src value
else:
$imageUrl = get_template_directory() . \'PATH TO YOUR DEFAULT IMAGE\';
endif;
希望有帮助!