PHP条件必选PHP / CSS不能在ie9中工作


Styles.php Conditional PHP / CSS not working in IE 9

我有一个style.php设置,使用以下代码调用:

<?php include (TEMPLATEPATH . '/includes/css/styles.php');?>

这个样式表包含以下代码:

<?php $thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'title-image', true);
$thumb_url = $thumb_url_array[0]; ?>
<style>
/* GET FEATURED IMAGE FOR TITLE BACKGROUND */
.titlearea {
<?php if(has_post_thumbnail()): ?>
background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
<?php else: ?>
background: url('http://www.example.com/wp-content/themes/my-custom-theme/includes/images/services-top.jpg');
<?php endif; ?>
background-size: cover;
background-position: 50% 0;
}
</style>

它应该寻找一个post缩略图(我使用Wordpress),并显示作为背景图像,如果有一个,如果页面没有缩略图,那么它应该回退到默认值(services-top.jpg)。

这段代码在chrome和Firefox中工作得很好,但是IE9只是显示一个白色背景,它甚至没有注册备用默认图像。

有人知道为什么这不起作用吗?

谢谢

PHP在服务器上运行。您的问题是IE9不支持linear-gradient。引用这个答案:

最好的跨浏览器解决方案是

background: #fff;
background: -moz-linear-gradient(#fff, #000);
background: -webkit-linear-gradient(#fff, #000);
background: -o-linear-gradient(#fff, #000);
background: -ms-linear-gradient(#fff, #000);/*For IE10*/
background: linear-gradient(#fff, #000);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff', endColorstr='#000000');/*For IE7-8-9*/ 
height: 1%;/*For IE7*/

谢谢你的回答@Mooseman

你的回答帮助了我,我得到了风格的功能与这段代码:

.titlearea {
<?php if(has_post_thumbnail()): ?>
    /*IE7-*/ background:            url('http://example.com/default.jpg');
    /*IE8+*/ background:            url('http://example.com/default.jpg');
    background:                     -webkit-linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
    background:                     -moz-linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
    background:                     -ms-linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
    background:                     -o-linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
    background:                     linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
<?php else: ?>
    background:                     url('http://example.com/default.jpg');
<?php endif; ?>
    background-size:                cover;
    background-position:            50% 0;
}