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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?