2017-02-13 3 views
1

Ich versuche, eine PHP-Datei in eine Seite mit WordPress zu integrieren. Allerdings hat alles nicht funktioniert.Wie füge ich PHP-Datei auf Wordpress-Seite

Ich fand etwas interessantes, aber es funktioniert nicht und ich frage mich, ob Sie mir helfen können.

Grundsätzlich versuche ich ein Plugin zu machen, um PHP-Datei in einer Seite hinzuzufügen.

<?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'); 
 

 
?>

Ich weiß nicht, wie hier PHP-Code hinzufügen, sorry.

Ich tippe [phpinclude file = 'Namefile'] auf meiner Seite.

+0

https://codex.wordpress.org/Writing_a_Plugin vielleicht ?? –

+0

Ich habe gelesen, aber ich bin mir nicht sicher, es zu verstehen. Der Code oben scheint für nichts so kompliziert zu sein, aber etwas funktioniert nicht und ich kann nicht herausfinden, was es ist. – AlexCold

Antwort

0

Ich tat das und es funktioniert.

Allerdings weiß ich nicht, ob der Code in Ordnung und speichern ist.

// 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'); 
 

 
?>

Verwandte Themen