如何在WordPress php模板中包含PHP文件?

时间:2015-04-29 14:39:22

标签: php wordpress

这是php代码中的代码:

include('/wp-content/custom-php/numberedSteps.php'); 

我收到了这个错误:

  

警告:include(/wp-content/custom-php/numberedSteps.php):无法打开流:

     

第85行/home/user/public_html/website.com/wp-content/themes/flatsome/woocommerce/archive-product.php中没有此类文件或目录

     

警告:include():打开失败' /wp-content/custom-php/numberedSteps.php'在/home/user/public_html/website.com/wp-content/themes/flatsome/woocommerce/archive-product.php中包含(include_path ='。:/ usr / local / php56 / pear')第85行

如何修复此错误?

2 个答案:

答案 0 :(得分:0)

试试这个

       include (get_theme_root().'/template-name/file-name.php'); ?>

此致

答案 1 :(得分:0)

尝试先获取根路径

for PHP> = 5.3.0试试

include(__DIR__.'/wp-content/custom-php/numberedSteps.php');

对于PHP< 5.3.0尝试

include(dirname(__FILE__).'/wp-content/custom-php/numberedSteps.php');