Conditonal statement for iPad

时间:2011-06-23 作者:chris_s

我需要隐藏我博客的品牌部分,但只有当有人在iPad上查看时。我不知道如何攻击这一点。

编辑:功能remove_access 目前可以在我的模板中使用,但我需要添加iPad功能。

因此,这对于试图隐藏该区域是否正确:

<?php 
function remove_access() {
 if(is_page(array(63, 386, 391, 405, \'forums\'))) {
    remove_action(\'thematic_header\',\'thematic_blogtitle\',3);
    remove_action(\'thematic_header\', \'thematic_blogdescription\',5);
    remove_action(\'thematic_header\', \'thematic_brandingclosing\',7);
    remove_action(\'thematic_header\',\'thematic_access\',9);
    remove_action(\'thematic_footer\',\'thematic_siteinfoopen\',20);
    remove_action(\'thematic_footer\',\'thematic_siteinfo\',30);
  }
}
if( preg_match(\'/ipad/i\',$_SERVER[\'HTTP_USER_AGENT\']) ){
    add_action(\'template_redirect\', \'remove_access\');
}
编辑-3:

完整功能

将条件更改为:如果(它是iPad,页面是博客)或(如果它是数组中的一个页面),则删除项目。

<?php
function remove_access() {
    if( preg_match(\'/ipad/i\',$_SERVER[\'HTTP_USER_AGENT\']) && is_page(\'blog\') || is_page(array(63, 386, 391, 405, \'forums\')) ){
        remove_action(\'thematic_header\',\'thematic_blogtitle\',3);
        remove_action(\'thematic_header\', \'thematic_blogdescription\',5);
        remove_action(\'thematic_header\', \'thematic_brandingclosing\',7);
        remove_action(\'thematic_header\',\'thematic_access\',9);
        remove_action(\'thematic_footer\',\'thematic_siteinfoopen\',20);
        remove_action(\'thematic_footer\',\'thematic_siteinfo\',30);
    }
}

add_action(\'template_redirect\', \'remove_access\');
编辑-4:

添加一个从子页面删除的函数。我试过这个,但似乎不起作用:

function remove_access() {
if( preg_match(\'/ipad/i\',$_SERVER[\'HTTP_USER_AGENT\']) && is_page(\'blog\') && ($post->post_parent == \'blog\') || is_page(array(63, 386, 391, 405, \'forums\')) && ($post->post_parent == (63, 386, 391, 405, \'forums\')) ){
    remove_action(\'thematic_header\',\'thematic_blogtitle\',3);
    remove_action(\'thematic_header\', \'thematic_blogdescription\',5);
    remove_action(\'thematic_header\', \'thematic_brandingclosing\',7);
    remove_action(\'thematic_header\',\'thematic_access\',9);
    remove_action(\'thematic_footer\',\'thematic_siteinfoopen\',20);
    remove_action(\'thematic_footer\',\'thematic_siteinfo\',30);
  }
}

add_action(\'template_redirect\', \'remove_access\');

2 个回复
最合适的回答,由SO网友:Milo 整理而成

没有简单易行的方法可以做到这一点,但一个快速而简单的解决方案是查看http用户代理:

<?php
if( preg_match(\'/ipad/i\',$_SERVER[\'HTTP_USER_AGENT\']) ):
    echo "is iPad";
endif;

SO网友:GavinR

您想使用WURFL, 它是一个不断更新的开源设备描述存储库。跟随these instructions 在Wordpress安装上设置API,然后您可以查询WURFL数据库中的“WURFL ID: apple_ipad_ver1“”

结束

相关推荐