2017-02-13 69 views
1

我正在嘗試使用wordpress在頁面中包含php文件。 但是,一切都沒有奏效。如何在wordpress頁面上添加php文件

我發現了一些有趣的東西,但它不起作用,我想知道如果你能幫助我。

基本上,我試圖做一個插件來添加一個頁面中的PHP文件。

<?php 
 

 

 

 
// include PHP file 
 
function PHP_Include($params = array()) { 
 

 
\t extract(shortcode_atts(array(
 
\t  'file' => 'default' 
 
\t), $params)); 
 
\t 
 
\t ob_start(); 
 
\t include(get_theme_root() . '/' . get_template() . '/folder' . "/$file.php"); 
 
\t return ob_get_clean(); 
 
} 
 

 

 
// register shortcode 
 
add_shortcode('phpinclude', 'PHP_Include'); 
 

 
?>

我不知道怎麼在這裏添加PHP代碼,對不起。

我在我的頁面輸入[phpinclude file ='namefile']。

+0

https://codex.wordpress.org/Writing_a_Plugin可能? –

+0

我正在閱讀,但我不確定要理解。 上面的代碼似乎沒有這麼複雜,但沒有任何工作,我不知道它是什麼。 – AlexCold

回答

0

我這樣做,它的工作原理。

但是,我不知道代碼是否正常並保存。

// include PHP file 
 
function PHP_Include($atts) 
 
{ 
 
\t 
 
    \t extract(shortcode_atts(array(
 
     'file' => 'default' 
 
    \t ), $atts)); 
 
\t 
 
\t 
 
\t include get_theme_root() . '/' . get_template() . '/chart/' . $file; 
 
\t 
 
} 
 

 
// register shortcode 
 
add_shortcode('phpinclude', 'PHP_Include'); 
 

 
?>

相關問題