doufangpian5545 2016-07-27 22:08
浏览 40
已采纳

Wordpress:is_ios()函数无法正常工作

I've been trying to use the is_ios() function but it doesn't seem to work. Once the page is compiled where I put my php code using the is_ios() it becomes blank.

This is the footer portion of a Wordpress document.

<?php if ( is_ios() ) : ?>
    <a href="instagram://user?username=USERNAME">
<?php else : ?>
   <a href="http://www.instagram.com/USERNAME">
<?php endif; ?>
<i class="fa fa-instagram fa-2x" aria-hidden="true"></i></a>

If I were to change <?php if ( is_ios() ) : ?> to <?php if ( wp_is_mobile() ) : ?> the code would run fine.

I'm not sure if I need to include something or anything. After looking at the docs for it (https://developer.wordpress.org/reference/classes/wp_customize_manager/is_ios/) I checked to see if the function existed in the correct place and it did. I don't know what else to try. Any insight or help would be appreciated.

FULL CODE

<?php
/**
 * The template for displaying the footer
 *
 * Contains the closing of the #content div and all content after
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
 ?>

<footer class="footer text-center">
    <div class="container">
        <p><strong>
        <i class="fa fa-copyright" aria-hidden="true"></i> USERNAME 
        </strong> <a href="#"><i class="fa fa-facebook-square fa-2x" aria-hidden="true"></i></a> 
        <a href="https://twitter.com/USERNAME"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"></i></a> 
        <?php if ( is_ios() ) : ?>
            <a href="instagram://user?username=USERNAME">
        <?php else : ?>
            <a href="http://www.instagram.com/USERNAME">
        <?php endif; ?>
        <i class="fa fa-instagram fa-2x" aria-hidden="true"></i></a>
        <a href="#"><i class="fa fa-envelope fa-2x" aria-hidden="true"></i></a>
        </p>

    </div>
  </footer>
  <?php wp_footer(); ?>
  </body>
</html>
  • 写回答

1条回答 默认 最新

  • douju1928 2016-07-28 04:52
    关注

    is_ios is a method of WP_Customize_Manager class. So you need to first create an instance:

    <?php 
    
    include_once('wp-includes/class-wp-customize-manager.php');
    
    $customizeManager = new WP_Customize_Manager();
    
    if ( $customizeManager->is_ios() ) : // etc. ?>
    

    Otherwise you can just copy the whole code:

    <?php if ( wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ) ) : // etc. ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?