If less than IE9

时间:2014-09-15 作者:MTuttle

我已经设置了两个侧栏,正在运行php浏览器检测插件:http://wordpress.org/plugins/php-browser-detection/ 我正在尝试使用下面的代码显示Internet上的倒计时ie侧边栏Explore少于版本9。不幸的是,IE 9仍在倒计时边栏中。

<?php if (is_lt_IE9()) : ?> 
    <?php if (function_exists(\'dynamic_sidebar\') && dynamic_sidebar (\'countdown-ie\')) : else : ?> 
        <div class="pre-widget"> <p><strong>Widgetized area 1</strong></p> 
        <p>This panel is active and ready for you to add some widgets via the WP Admin</p> 
        </div> 
    <?php endif; ?> 
<?php else : ?> 
    <?php if (function_exists(\'dynamic_sidebar\') && dynamic_sidebar (\'countdown\')) : else : ?                 > 
      <div class="pre-widget"> <p><strong>Widgetized area 2</strong></p> 
      <p>This panel is active and ready for you to add some widgets via the WP Admin</p> 
      </div> 
    <?php endif; ?> 
<?php endif; ?> 
这里有一个链接:http://steveabraham.com/

有人知道我做错了什么吗?

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

这是我对您的代码的修订版本:

<?php
if( is_ie() && get_browser_version() < 9 ) {
    if ( is_active_sidebar( \'countdown-ie\' ) ) {
        dynamic_sidebar( \'countdown-ie\' );
    } else {
        ?>
        <div class="pre-widget">
            <p><strong>Widgetized area 1</strong></p> 
            <p>This panel is active and ready for you to add some widgets via the WP Admin</p> 
        </div>
        <?php
    }
} else {
    if ( is_active_sidebar( \'countdown\' ) ){
        dynamic_sidebar (\'countdown\');
    } else {
        ?>
        <div class="pre-widget">
            <p><strong>Widgetized area 2</strong></p>
            <p>This panel is active and ready for you to add some widgets via the WP Admin</p>
        </div>
        <?php
    }
}
变更日志:

您的初始检查现在使用is_ieget_browser_version 函数修复了PHP标记垃圾邮件。无需将每条语句都封装在PHP标记中,只需额外输入切换到的原始条件语法if () {} else {} 为了简化缩进HTML,删除了尾随空格,修复了一个中断的结束PHP标记? >is_active_sidebar

  • 一些wordpress编码标准修复了最后一个注意事项,您不应该嗅探用户浏览器。如果启用了缓存,则此代码将失败(用户1在IE上,页面被缓存,用户2在firefox上,但看到缓存的IE页面..)

  • 结束

    相关推荐