dtxw20878 2018-10-03 07:33
浏览 65
已采纳

在word press中包含父sibling文件夹中的PHP文件

I try to include some PHP file to another one by using include function. It works fine when files are at the same directory that simply can do

include (file.php)

and if a file is in the child folder like

include (folder/file.php).

but I want to make my root WordPress folder project cleaner then change the location of my template files to pages-template folder but unfortunately, I can't include files from another folder that are the sibling with pages-template. I try this

include '../inc/package-save.php';

but I got errors

Warning: include(../inc/package-save.php): failed to open stream: No such file or directory

any trick to fix this.

  • 写回答

2条回答 默认 最新

  • dongma7725 2018-10-03 07:59
    关注

    Finally, I found the solution. just put the dirname(__FILE__) function before the directory that I want to include.

    This function will get the directory path that files that I write this function to it.

    for example, if file be at C:\xampp\htdocs\amt-master\wp-content\themes\wp-bootstrap-child it returns this path

    But as my case, I want to get the previous path to do that I should just put this function in the same function like this

    include dirname(dirname(__FILE__))."/filename.php"

    then it will return this path

    C:\xampp\htdocs\amt-master\wp-content\themes

    then you can write remaining path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误