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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题