Home > php教程 > php手册 > body text

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect,wordpress-mobile

WBOY
Release: 2016-06-13 09:03:52
Original
1016 people have browsed it

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect,wordpress-mobile

wordpress如何判断是手机、平板还是PC访问,并针对性的显示特定的内容?Mobile Detect 这个轻量级PHP 类库能够很好的实现这个功能。而且Mobile Detect也有wordpress下的插件可用–WP Mobile Detect,wordpress使用这个插件,很容易实现根据不同终端设备显示特定内容的功能,比如响应式wordpress主题。

安装WP Mobile Detect插件

登录wordpress管理后台,在插件管理页面选择“安装插件”,然后再搜索框里输入关键字“WP Mobile Detect”,然后再搜索结果页面李选择“WP Mobile Detect”并安装即可。

安装WP Mobile Detect插件

 

搜索WP Mobile Detect插件

WP Mobile Detect如何使用

在wordpress的文章编辑器里用[关键字]进行标注,例如

Mobile Detect 如何使用

 

或者在php代码里用函数进行判断

wpmd_is_notphone() – Returns true when on desktops or tablets
wpmd_is_nottab() – Returns true when on desktops or phones
wpmd_is_notdevice() – Returns true when on desktops only
wpmd_is_phone() – Returns true when on phones ONLY
wpmd_is_tablet() – Returns true when on Tablets ONLY
wpmd_is_device() – Returns true when on phones or tablets but NOT destkop
wpmd_is_ios() – Returns true when on an iOS device
wpmd_is_iphone() – Returns true when on iPhones
wpmd_is_ipad() – Returns true when on iPads
wpmd_is_android() – Returns true when on Android
wpmd_is_windows_mobile() – Returns true when on Windows Mobile

 

例如:

 

1 2 3 4 5 6 7 8 9 10 11 12 13 <?php if(wpmd_is_phone()){ ?> <div> <code class="php plain">仅手机可见内容 <?php } else if(wpmd_is_tablet()){ ?> <div> <code class="php plain">仅平板电脑可见内容 <?php } else { ?> <div> <code class="php plain">仅PC可见内容 <?php } ?>

原创文章,转载请注明: 转载自 吴川斌的博客 http://www.mr-wu.cn/

本文链接地址: wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect http://www.mr-wu.cn/mobile-detect-wordpress-plugin/

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template