首页 文章

WordPress子目录中的子主题文件没有覆盖

提问于
浏览
2

我正在使用子主题修改WordPress主题 . 在我的子主题文件夹中,我创建了一个名为“includes”的文件夹(就像父文件一样),并对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

http://systemspecialist.net/2013/04/16/add-customized-files-includes-folder-to-wordpress-child-theme/

我也试过这个解决方案并得到相同的500错误:WordPress Child Theme including includes files

1 回答

  • 0

    get_stylesheet_directory()返回绝对服务器路径(例如:/ home / user / public_html / wp-content / themes / my_theme),而不是URI .

    您的代码可能转换为绝对URL

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

相关问题