2013-11-14 112 views
-1

截至目前,我在我的Wordpress主題中的一個模板中包含此代碼。在Wordpress模板中包含PHP文件

// blah blah 

     <div class="content"> 

      <?php include_once('http://www.website.com/new/file.php?variable=1'); ?> 

     </div> 

// blah blah 

現在,它會加載此模板中的所有內容,除了這個php包含!這將加載其中包括上面的/ *等等等等*側邊欄/當我檢查元素在谷歌瀏覽器將加載頁腳,導航等

它顯示了這一點:

<div class="content"> 

     (it's empty) 

</div> 

請幫助我,如果你知道我做錯了什麼!謝謝!

+1

那麼,是什麼,當你在瀏覽器中打開一個PHP文件輸出呢? –

+0

而不是使用包括相似的功能的,抓住從URL內容和迴音吧'回聲的file_get_contents(「http://www.website.com/new/file.php?variable=1」);' –

+0

是您的網站上'http:// www.website.com'(即與包含文件相同的域)?如果沒有,你應該使用file_get_contents或其他東西。 – Matt

回答

4

includerequire不走的URL。他們採取服務器文件路徑。試試這個:

<?php include_once(ABSPATH.'/new/file.php'); ?> 

編輯:忘了提,查詢字符串不能包含在文件路徑。如果查詢字符串是必要進行適當的負荷,考慮加載頁面,在當前的URL所有必要的查詢變量,裝載部分使用iframe,或者使用file_get_contents()

的Iframe:

<iframe src="http://www.website.com/new/file.php?variable=1"></iframe> 

file_get_contents()函數

<?php echo file_get_contents('http://www.website.com/new/file.php?variable=1'); ?> 
+0

警告:include_once(/home/username/public_html/new/file.php?variable=1)[function.include-once]:無法打開流:沒有這樣的文件或目錄在/ home/username/public_html/new /可溼性粉劑內容/主題/ THEME1 /在線template_home.php 30 這就是我得到的..我知道那裏的文件,因爲我可以得到在瀏覽器/new/file.php?variable=1和它的作品.. 編輯:當我刪除?變量= 1時,它的作品..但我需要那個變量? –

+0

看看路徑。爲什麼當你在尋找/new/file.php時,它指向/ new/wp-content/themes /? – maiorano84

+0

我不知道..但我工作時,我刪除'?變量= 1'。我想它說,說源文件是..因爲我的模板源在該模板(template_home.php) –