我正在使用子主题修改WordPress主题。在我的子主题文件夹中,我创建了一个名为"包含"的文件夹。 (就像父母一样)并且已经对content-post.php,content-single.php和content-single-portfolio.php文件进行了编辑。我已经添加到子文件夹中的functions.php文件中:
require_once( get_stylesheet_directory() . 'includes/content-post.php' );
require_once( get_stylesheet_directory() . 'includes/content-single.php' );
require_once( get_stylesheet_directory() . 'includes/content-single-portfolio.php' );
这导致500内部错误,我不确定原因。
参考: http://codex.wordpress.org/Child_Themes
我也试过这个解决方案并得到相同的500错误: WordPress Child Theme including includes files
答案 0 :(得分:0)
返回绝对服务器路径(例如: / home / user / public_html / wp-content / themes / my_theme),而不是URI。
您的代码可能转换为绝对网址,如
/home/user/public_html/wp-content/themes/my_themeincludes/content-single-portfolio.php
get_stylesheet_directory()应始终后跟正斜杠
require_once( get_stylesheet_directory() . '/includes/content-post.php' );
您最好的选择是检查错误日志,大多数500错误消息与php超时有关,特别是如果该网站以前在您进行任何php修改之前工作正常。
您也可以尝试为每个文件逐个执行此类操作
//Checking if file exist
if ( file_exists( get_stylesheet_directory() . '/includes/content-post.php') ) {
//Require file if it exist,
require_once( get_stylesheet_directory() . '/includes/content-post.php' )
} else {
/* Echo something if file doesn't exist, if the message wasn't displayed and you still get 500 error then there's some wrong on the php file above*/
_e('File not found');
}