2010-08-07 101 views
1

我試圖在/ html /目錄的開頭添加一個文件(/wp-load.php)。我試圖從/wp-content/themes/pw-steel-orange/index-load.php包括它,但我總是得到錯誤信息需要wp-load.php 3個目錄返回

Warning: require_once(../wp-load.php) [function.require-once]: failed to open stream: No such file or directory in /nfs/c07/h01/mnt/102799/domains/platyworld.com/html/wp-content/themes/pw-steel-orange/index-load.php on line 1

Fatal error: require_once() [function.require]: Failed opening required '../wp-load.php' (include_path='.:/usr/local/php-5.2.6-1/share/pear') in /nfs/c07/h01/mnt/102799/domains/platyworld.com/html/wp-content/themes/pw-steel-orange/index-load.php on line 1

難道我做錯了什麼?我雖然../帶來的包括到開始的目錄

很抱歉,如果這是一個重複,我找不到我的搜索與此相關的東西...

+2

當然,WordPress應該加載你的主題文件,而不是其他方式。除非你真的必須,否則我不會推薦加載wo-load.php。 – dave1010 2010-09-23 15:18:51

回答

2

可以發出以下命令來查看你從哪裏下載文件:

// get your current working directory 
echo getcwd(); 

然後包括相應的文件。

// file is 3 dirs back 
include '../../../wp-load.php'; 

如果您使用的是像笨的框架,例如,將有你的應用程序將調用其他所有代碼的最開始的index.php文件。所以你必須根據該文件包含該文件。

大多數框架使用他們稱之爲BASEPATH的東西,這是當前實際的完整服務器路徑到站點。將您的網站遷移到其他目的地時,這可能非常有用。

+0

很奇怪......我嘗試了../../../wp-load.php幾次,到現在爲止它不工作......謝謝! – sman591 2010-08-07 02:02:47

+1

@ sman591 3級退後是一個瘋狂的猜測......! :)我只是想通過'getcwd'告訴你如何查看你的位置,然後進行相應的調整。但我很高興它的工作! ;) – Frankie 2010-08-07 02:05:12

+0

http://ottopress.com/2010/dont-include-wp-load-please/ – 2012-08-18 06:31:00

1

這裏是一個半自動化的方式來做到這一點:

$incPath = str_replace("/wp-content/plugins/PLUGIN_NAME","",getcwd()); 
ini_set('include_path', $incPath); 
include('wp-load.php'); 

無論不過,它仍然是一個bad idea to include wp-load.php。 (如果這個鏈接被刪除,See that page here