2013-06-24 29 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