2013-06-24 36 views
0

這是我第一次決定將第三方API集成到我的主題中,所以請在這裏裸露一些這些問題可能是基本的。如何在php中設置模板路徑include for wordpress API

我有以下要填寫,但對於我的生活,我無法得到這個閱讀get_template_directory_uri();爲了該文件被正確包括。這會導致頁面加載到該腳本的運行,但隨後會打破所有內容(空白)。

編輯:我已經包括循環結束/重新啓動點,以防這是wordpress問題。

  <?php endwhile; ?> 
      <?php wp_reset_postdata(); ?> 
      </div> 
    </div> 


<div id="firstpost" class="topfirstpost"> 

    <?php 
    include (get_template_directory_uri().'/lib/forecast.io.php'); 

    $api_key = '<tempkey>'; 

    $latitude = '49.261226'; 
    $longitude = '-123.113927'; 


    $forecast = new ForecastIO($api_key); 


    /* 
    * GET CURRENT CONDITIONS 
    */ 
    $condition = $forecast->getCurrentConditions($latitude, $longitude); 

    echo $condition->getTemperature(); 

    ?> 

</div> 

<div id="secondpost" class="topsecondpost"> 

<?php 
       $first_query = new WP_Query('cat=2&showposts=1&offset=2'); 
       while($first_query->have_posts()) : $first_query->the_post(); 
      ?> 

這是forecast.io api的一個片段,如果有人想知道。

回答

0

你試過添加一個/?

include(get_template_directory_uri().'/lib/forecast.io.php'); 
+0

是的我已經試過了。仍然導致其後的一切都變黑。 – canacast

0

我認爲這可能是get_template_directory_uri()返回一個HTTP的方向,和PHP的一些版本不支持遠程文件訪問,我會嘗試使用它只有這樣

include('lib/forecast.io.php'); 
+0

不幸的是,這也不起作用,所以我仍然相信這個API API正在破裂...無論如何。如果更多的答案證明富有成效,將更新這個問題。 – canacast

0

我已經決定了這個預測。插件並不是非常友好的API,但圖標仍然非常棒,我敢肯定,它將在未來一直辜負炒作。

在那之前,我用這個代替

http://simpleweatherjs.com