Failed opening required /wp-content/themes//inc/template-tags.php

wordpress更换主题导致的异常,网站不能访问,看日志错误信息如下:

[Sat Mar 31 15:10:52 2018] [error] [client 58.221.92.194] PHP Warning: require(/xxx/wp-content/themes//inc/template-
tags.php): failed to open stream: No such file or directory in /xxx/wp-content/themes/simple-melody/functions.php on line
170
[Sat Mar 31 15:10:52 2018] [error] [client 58.221.92.194] PHP Fatal error: require(): Failed opening required '/xxx/wp-
content/themes//inc/template-tags.php' (include_path='.:/usr/share/pear:/usr/share/php') in /xxx/wp-
content/themes/simple-melody/functions.php on line 170

网站不能访问,不能进入后台,还好网上有策略,可以通过数据库的修改,来恢复到出问题之前的状态。

SELECT *
FROM wp_options
WHERE option_name = 'template'
OR option_name = 'stylesheet'
OR option_name = 'current_theme';

mysql> select * from wp_options where option_name = 'template'
-> OR option_name = 'stylesheet'
-> OR option_name = 'current_theme';
+-----------+---------------+---------------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+---------------+---------------------+----------+
| 218 | current_theme | simple-melody-child | yes |
| 45 | stylesheet | simple-melody | yes |
| 44 | template | | yes |
+-----------+---------------+---------------------+----------+

发现option_value值不同,而且有些模板值根本连目录都已经不存在了,找到主题目录下存在的一个主题,比如“twentyeleven”这个目录是存在的,那么进行更新。

UPDATE wp_options SET option_value = 'twentyeleven' WHERE option_name = 'template';

UPDATE wp_options SET option_value = 'twentyeleven' WHERE option_name = 'stylesheet';

UPDATE wp_options SET option_value = 'twentyeleven' WHERE option_name = 'current_theme';

mysql> select * from wp_options where option_name = 'template' OR option_name = 'stylesheet' OR option_name = 'current_theme';
+-----------+---------------+--------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+---------------+--------------+----------+
| 218 | current_theme | twentyeleven | yes |
| 45 | stylesheet | twentyeleven | yes |
| 44 | template | twentyeleven | yes |
+-----------+---------------+--------------+----------+
3 rows in set (0.00 sec)

那么问题就解决了。。。。。。。。