2016-07-27 55 views
0

我一直在嘗試使用is_ios()函數,但它似乎並沒有工作。一旦頁面編譯完成後,我使用is_ios()將我的php代碼放到了空白處。WordPress的:is_ios()函數不工作

這是Wordpress文檔的頁腳部分。

<?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> 

如果我改變<?php if (is_ios()) : ?><?php if (wp_is_mobile()) : ?>代碼將運行正常。

我不確定是否需要包含任何內容。在查看文檔(https://developer.wordpress.org/reference/classes/wp_customize_manager/is_ios/)後,我檢查了該函數是否存在於正確的位置,並確實存在。我不知道還有什麼要嘗試。任何見解或幫助將不勝感激。

全碼

<?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

檢查日誌錯誤的詳細信息(或打開錯誤報告)。從你鏈接的文檔看,它看起來像是類「WP_Customize_Manager :: is_ios()」的一部分,所以你沒有正確調用它。 – ceejayoz

+0

@ceejayoz打開錯誤報告(很酷的東西),並簽出堆棧跟蹤。 '致命錯誤:未捕獲錯誤:調用未定義的函數is_ios()''所以我試圖改變函數內部的is_ios()''WP_Customize_Manager :: is_ios()'並得到一個新的錯誤'致命錯誤:未捕獲錯誤:類'找不到WP_Customize_Manager'。所以我覺得我需要以某種方式導入這個類? –

回答

0

is_iosWP_Customize_Manager類的方法。所以,你需要首先創建一個實例:

<?php 

include_once('wp-includes/class-wp-customize-manager.php'); 

$customizeManager = new WP_Customize_Manager(); 

if ($customizeManager->is_ios()) : // etc. ?> 

否則你可以複製整個代碼:

<?php if (wp_is_mobile() && preg_match('/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'])) : // etc. ?> 
+0

太棒了 - 非常感謝。使用'$ customizeManager-> is_ios()'是你如何使用PHP中的類的方法? –

+0

實際上,爲了使用一種方法創建此類的實例是相當矯枉過正的。這個類實際上是用於管理端的定製器。複製整個代碼也更安全......我會這樣做。 –