phpstorm不知道如何运行Wordpress [英] Phpstorm doesn't know how to run Wordpress

查看:367
本文介绍了phpstorm不知道如何运行Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尽力在这里找到所有信息并进行了谷歌搜索.包括路径,外部库,解释器设置...

I've tried all I could found here and googling. Include paths, external libraries, interpreter settings...

每当我尝试运行主题的index.php文件:

Whenever I try to run my theme's index.php file:

C:\XAMPP\php\php.exe "C:\path\to\project\wp-content\themes\MYTHEME\index.php"

Fatal error: Call to undefined function get_header() in C:\path\to\project\wp-content\themes\MYTHEME\index.php on line 1

Process finished with exit code 255

是的,在第1行,我只是在调用标题.

So yes on line 1 I'm just calling my header.

事实证明,它试图像独立文件一样运行index.php,但却忽略了整个Wordpress安装(我从不同角度进行了介绍).当然,现在它是get_header()的位置,因为我可以控制单击它,它将把我带到声明它的文件中,没问题.

Turns out it's trying to run index.php like a standalone file, but ignoring the whole Wordpress instalation (that I have included from different angles). Certainly it nows where get_header() is because I can control click it and it'll bring me to the file it's declared in, no problems.

它也可以正确检测XAMP的PHP解释器.

It correctly detects XAMP's PHP interpreter too.

如果我只是在浏览器中输入本地主机URL来访问该站点,它也将很好地工作.只是无法在Phpstorm中使用.

It also works well if I just visit the site typing my localhost URL in the browser. It just won't work through Phpstorm.

推荐答案

您正在直接调用主题索引文件,这是不正确的方式,因为您的主题必须使用WordPress的某些默认功能,例如get_header().

You are directly calling theme's index file which is not correct way, as your theme must be using some default functions of WordPress, like get_header() in this case.

因此,您需要确保已加载wp-load.php,以使所有WP函数都可以使用.您有两种方法:

So you need to make sure wp-load.php is loaded to make all WP functions available to use. You have two way for that:

1)调用root index.php,因此默认情况下将加载所有内容.

1) Call root index.php so everything will be loaded by default.

2)调用主题的index.php,但在其中添加以下代码:

2) Call theme's index.php but add Below code in that:

if(!function_exists('get_header')) {
    require_once( '/wp-load.php' );
}

但是这不是一个好方法:)

However this is not good way :)

这篇关于phpstorm不知道如何运行Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆