Why would adding a template file to a child theme cause an error in template-loader.php?

Per wordpress best practices, I created a child theme for an existing theme I have. Everything works fine until I try to add a template file which follows WP's template hierarchy conventions. For example, if I add category.php or archive.php, I get a white screen of death, and this is the error I get in Apache:

    [:error] [pid 2919] [client 98.24.106.38:64974] PHP Warning:  include(): 
Failed opening '/home/www-dev/beokinawa/wp-content/themes/x-child/index.php' for
 inclusion (include_path='.:/usr/share/php') in /home/www-dev/beokinawa/wp-
includes/template-loader.php on line 74, referer: 
http://dev.bluepresley.com/beokinawa/wp-admin/edit-tags.php?taxonomy=category

Whenever I try to view a category after uploading either of those files, the system wants to load the category edit screen url it seems. What could cause that? You can also see from the error that it's trying to find index.php, the last in the template hierarchy. If category.php or archive.php are present then there would be no reason for it to look for that file, right?

That the issue would be permissions is interesting. Here is a breakdown of permissions.

  • files are chown'ed user:www-root
  • per wordpress documentation, files are 664 ( even changed the directory and files to 777 briefly, but that didn't work either)

It seems I cannot add any additional files from the wordpress template hierarchy scheme. But, editing template parts is fine. The parent theme comes with wp-header.php, wp-footer.php, etc, and I can add those and overrides happen correctly.

Topic fatal-error child-theme templates errors Wordpress

Category Web


Your initial idea is correct, WordPress shouldn't look for index.php if it finds category.php for a category archive. However, that may change if you don't have file permission and ownership set properly, or if FileSystem cache is messing with file_exists() check.

Follow these steps:

  1. Make sure your child theme files are readable by the web server user. Check both file permission and ownership.

  2. Check to see if the child theme is coupled properly with the parent theme and it can get templates from parent theme if any specific template is absent in the child theme.

  3. In wp-config.php use clearstatcache(); function (before require_once(ABSPATH . 'wp-settings.php');) to clear filesystem cache.

    In case you were adding & removing those files while testing and filesystem caching those files, clearstatcache(); will help you clearing those filesystem cache that may confuse WordPress core. Once done, remove clearstatcache(); call.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.