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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示