dongye3917 2014-06-13 13:55
浏览 67
已采纳

Styles.php条件PHP / CSS在IE 9中不起作用

I have a style.php setup which is being called using this code:

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

This style sheet contains this code:

<?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>

Which should look for a post thumbnail (im using Wordpress) and display that as the background image if there is one, if the page doesnt have a thumbnail then it should fallback to the default (services-top.jpg).

This code is working great in Chome and Firefox but IE9 is just showing a white background, its not even registering the fallback defautl image.

Anyone know why this isnt working?

Thanks

  • 写回答

2条回答 默认 最新

  • dregduc63699 2014-06-25 11:18
    关注

    Thanks for your answer @Mooseman

    Your answer helped and I got the style functioning as wanted with this code:

    .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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化