【问题标题】:require core wordpress php files需要核心 wordpress php 文件
【发布时间】:2014-11-04 10:12:25
【问题描述】:

我在 wordpress 网站上使用 angular 来生成动画页面过渡。 angular HTML 代码由 PHP 在 wordpress 自定义模板中生成,我设置了 angular 来获取单个 php 文件。

当 php 文件通过 angular 获取时,基本的 php 代码可以正常执行。但是,找不到任何与 wordpress 相关的内容。我猜是因为 wordpress php 文件已经在初始页面加载时执行了。

我在 php 文件中使用了 require 并给出了我正在使用的一些文件的路径,但它们仍然需要 wordpress php 文件才能运行,因此它们会抛出 500 (Internal Server Error)

<div id="pageone">
    <p>This is page 1.</p>
    <a href="#page2">Go to page 2 </a><br>

    <?php

echo ('this php line works');

require './../../lib/custom.php';
echo ('this file is found, but needs wordpress functions, so throws 500 error');

    ?>
</div>

我想我可以使用 require 来获取核心的 wordpress php 文件,但我不知道那是哪个 php 文件..

【问题讨论】:

    标签: php angularjs wordpress


    【解决方案1】:

    对于任何想知道的人来说,wordpress 的核心 php 文件(无论如何都是根主题)位于

    web/wp/wp-load.php

    require './../../../../../wp/wp-load.php';
    

    来自 wp-load 的简介

    /**
     * Bootstrap file for setting the ABSPATH constant
     * and loading the wp-config.php file. The wp-config.php
     * file will then load the wp-settings.php file, which
     * will then set up the WordPress environment.
     *
     * If the wp-config.php file is not found then an error
     * will be displayed asking the visitor to set up the
     * wp-config.php file.
     *
     * Will also search for wp-config.php in WordPress' parent
     * directory to allow the WordPress directory to remain
     * untouched.
     *
     * @internal This file must be parsable by PHP4.
     *
     * @package WordPress
     */
    

    【讨论】:

    • 在正常的 WP 安装中,它只是在 WP 根文件夹中。
    • 我怀疑你是loading WP two times。如果是自定义模板,应该有一个入口点来避免这种情况。
    • 你显示的代码还不够……和你的自定义模板有什么关系?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多