如何在php中为wordpress API设置模板路径


How to set template path within 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的一个片段。

您尝试添加/了吗?

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

我认为可能是get_template_directory_uri()返回了http方向,而php的某些版本不支持远程文件访问,我会尝试只像这个一样使用它

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