douchao5864
2015-04-29 14:39
采纳率: 100%
浏览 40
已采纳

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

This is the code I have inside php tags:

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

And I get this error:

Warning: include(/wp-content/custom-php/numberedSteps.php): failed to open stream:

No such file or directory in /home/user/public_html/website.com/wp-content/themes/flatsome/woocommerce/archive-product.php on line 85

Warning: include(): Failed opening '/wp-content/custom-php/numberedSteps.php' for inclusion (include_path='.:/usr/local/php56/pear') in /home/user/public_html/website.com/wp-content/themes/flatsome/woocommerce/archive-product.php on line 85

How can this error be fixed?

图片转代码服务由CSDN问答提供 功能建议

这是我在 php 标签内的代码: \ ñ

 <代码>包括( '/可湿性粉剂内容/定制的PHP / numberedSteps.php');  
   
 
 

我收到此错误:

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

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

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

如何修复此错误?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doubanduo7620 2015-04-29 14:44
    已采纳

    try getting the root path first

    for PHP >= 5.3.0 try

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

    For PHP < 5.3.0 try

    include(dirname(__FILE__).'/wp-content/custom-php/numberedSteps.php');
    
    打赏 评论
  • dongtangjie0495 2015-04-29 14:42

    Try this

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

    Regards

    打赏 评论

相关推荐 更多相似问题