Warning when using

Would need some more help with the

Did ask a question how to import some code with php, in this case it’s a sidebar that will be used on some of the pages on a website, It’s wordpress and it can execute php from post / page’s and have also tested directly in the main code

When i did ask the question the best and most easy thing would be to create a file and use include

Did create thefile.php and did put it in the theme dir where all other .php file’s used is, In the file i did just put some basic html like

<div id=the-id"> 
      <p> a test text </p>
</div> 

Then i did put the include code writen as below in my template

<?php include 'thefile.php'; ?>

Doing this i see my text “a test text” but also get several warning’s

 Warning: include(/wp-content/themes/thetheme/thefile.php) [function.include]:       failed to open stream: No such file or directory in /home/cplac/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 22

And also this

Warning: include() [function.include]: Failed opening ‘/wp-content/themes/thetheme/thefile.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php:/home/cplac/public_html/wp-content/plugins/wpsyndicator:/home/cplac/public_html/wp-content/plugins/wp-external-links/includes/phpQuery/:/home/cplac/public_html/wp-content/plugins/wp-external-links/includes/phpQuery/plugins/’) in /home/cplac/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 22

Someone that can help me out whit this ? Have tested both in pages but also in the theme files and so on !

3 Answers
3

The WordPress method to include php files is to use this function:

<?php get_template_part('myfile'); ?>

which will include the file myfile.php that is in the same template directory.

See http://codex.wordpress.org/Function_Reference/get_template_part for other parameters.

Leave a Comment