这是我第一次决定将第三方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的一个片段,如果有人想知道。
是的我已经试过了。仍然导致其后的一切都变黑。 – canacast