且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在wordpress中运行php应用程序

更新时间:2023-02-22 23:17:26

这是***的方法。这样做是为了保留要插入的应用程序的文件夹结构。路径应该仍然工作,它们是相对于文件所以仍然应该工作。

The best way to do this is to preserve the folder structure of the application you want to insert. This way paths should still work, they are relative to the file so should still work.

所以
1.在您的主题中创建一个新文件夹名为repairstatus

so 1. create a new folder in your theme called "repairstatus"


  1. 将所有文件上传到 - index.php等

  1. upload all the files into that -- index.php etc

将以下代码放在主题中函数functions.php(或创建子主题

Place the following code in your themes functions.php (or create a child theme

//1. add a wp query variable to redirect to
add_action('query_vars','plugin_set_query_var');
function plugin_set_query_var($vars) {
    array_push($vars, 'is_repair_page'); // ref url redirected to in add rewrite rule

    return $vars;
}


//2. Create a redirect
add_action('init', 'plugin_add_rewrite_rule');
function plugin_add_rewrite_rule(){
    add_rewrite_rule('^repairstatus$','index.php?is_repair_page=1','top');

    //flush the rewrite rules, should be in a plugin activation hook, i.e only run once...

    //flush_rewrite_rules();  
}

//3.return the file we want...
add_filter('template_include', 'plugin_include_template');
function plugin_include_template($template){


    // see above 2 functions..
    if(get_query_var('is_repair_page')){
        //path to your template file
        $new_template = get_stylesheet_directory().'/repairstatus/index.php';
        if(file_exists($new_template)){
            $template = $new_template;
        } 
        // else needed? up to you maybe 404?
    }    

    return $template;    

}


现在,导航到管理仪表板上的设置,然后点击固定链接。只需点击保存按钮。在此阶段测试, http://accuratepctech.com/repairstatus/ 应该打开index.php(它会看起来有趣的一刻)。

Now navigate to settings on the admin dashboard and click on permalinks. Just hit the save button. test at this stage, http://accuratepctech.com/repairstatus/ should open index.php (it will look funny for the moment)..

现在mod index.php文件...所有我们需要做的是注释headerstatus和footerstatus要求,他们将打破html output ...

now mod the index.php file...all we need to do is comment out the headerstatus and footerstatus requires, they will break the html output...

我们可以使用 get_header()加载wp网站的标题, css,导航等和 get_footer()用于页脚元素。

We can use get_header() to load the header of the wp site which will load css, navigation etc. and get_footer() for the footer element.

    if (array_key_exists('func',$_REQUEST)) {

    $func = $_REQUEST['func'];

    } else {

    $func = "";

    }





    //loads header and related 
    get_header();


    function repairlookup() {

    require("deps.php");

    //require("headerstatus.php"); -->not needed, its only html

    require("common.php");

    //etc////////////


    //find require("footerstatus.php") and remove

    }

    get_footer();

现在你应该有一个wp寻找页面只是index.php代码将被取消。您可以使用

now you should have a wp looking page just the index.php code will be unstyled. You can add the css in by using

<link rel="stylesheet" type="text/css" href="style.css">

(注意这是html,关闭php标签才能使用它),但是id建议你打开这个文件,复制到你的style.css中你的主题,然后可以改变CSS以适应。

(note this is html, close php tags to use it) but id recommend you open this file and copy into your style.css in your theme, you can then change the css to suit.

请注意,这可能会按原样工作,但可能有错误,因此请检查操作。我要推荐你谷歌wpdb和更新使用WP数据库函数(你可以创建单独的表,如果你想要的)否则你有2 db连接在旅途中。这将不利于网站的性能,它将加载确定与1个用户,但3/4并发用户将开始减慢一切下来...

Note this will probably work as is, but there may be errors so check the operation throughly. I'm going to recommend you google wpdb and update to use WP database functions (you can create seperate tables if you want) otherwise you have 2 db connections on the go. This will not be good for the performance of the website, it will load ok with 1 user but 3/4 concurrent users will start to slow everything down...