Wordpress 包含 php 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26808290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress include php file
提问by Shashwat
I am trying to create a php website on WordPress
for the first time.
我正在尝试WordPress
第一次创建一个 php 网站。
When I create a page, it creates a permalink which is of the form http://localhost/?p=123
. I don't know if there is a corresponding file.
当我创建一个页面时,它会创建一个形式为http://localhost/?p=123
. 不知道有没有对应的文件。
I've installed insert-php
plugin to read php code. It works fine on a static page. But how do I include another php file? I want to include my_utilities
which contains all the back-end functions, in login
. It has a permalink 'http://localhost/?page_id=45'
.
我已经安装了insert-php
插件来读取 php 代码。它在静态页面上工作正常。但是如何包含另一个 php 文件?我想my_utilities
在login
. 它有一个固定链接'http://localhost/?page_id=45'
。
What to do?
该怎么办?
include 'http://localhost/?page_id=45'
doesn't work.
include 'http://localhost/?page_id=45'
不起作用。
回答by webeno
Pages you define in WordPress's backend are pages mostly setup for your users to view / read. They, by default, have this URL structure of http://localhost/?p=123
(though this can be changed, but that's a whole different lesson).
您在 WordPress 后端定义的页面主要是为您的用户设置以查看/阅读的页面。默认情况下,它们的 URL 结构为http://localhost/?p=123
(虽然可以更改,但这是一个完全不同的教训)。
To include a script file, upload the file to your folder structure where you have your website then refer to it in your include
statement as follows:
要包含脚本文件,请将文件上传到您的网站所在的文件夹结构,然后在您的include
语句中引用它,如下所示:
include('path/to/folder/my_script.php');
EDIT: You may also want to have a look into WordPress Page Templates:
编辑:您可能还想查看WordPress 页面模板:
Pages are one of WordPress's built-in Post Types. You'll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.
页面是 WordPress 的内置帖子类型之一。您可能希望您的大部分网站页面看起来都差不多。但有时,您可能需要一个特定的页面或一组页面来显示或表现不同。这可以通过页面模板轻松完成。
回答by Jonny Right
For exapmle your wordpress file is at
例如,您的 wordpress 文件位于
/var/www/html/wp-content/myphpfiles/test.php
/var/www/html/wp-content/myphpfiles/test.php
To include the test.php file in your wordpress page you have to following.
要将 test.php 文件包含在您的 wordpress 页面中,您必须遵循。
[insert_php] include('wp-content/myphpfiles/test.php'); [/insert_php]
Thats it.
就是这样。