且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将自定义页面模板添加到我的子主题

更新时间:2021-12-09 21:28:44

我无法通过全新安装的 WordPress 3.3.1 复制您所看到的内容.我有一个只有两个文件的主题,style.css,包含:

I can't duplicate what you're seeing with a clean install of WordPress 3.3.1. I have a theme with just two files, style.css, containing:

/*
Theme Name:     ***-8946077
Template:       twentyeleven
Version:        0.0.1
*/
@import url("../twentyeleven/style.css");

coming-soon.php,包含:

<?php
 /*
  Template Name: Coming Soon
 */

get_header();
?><h1>Coming Soon</h1><?php
get_footer();
?>

其中的第一部分是从您的问题中复制的.

the first part of which was copied from your question.

我看到了预期的模板:

我唯一能想到的就是仔细检查:

The only things I can think of are to double-check:

  • 该文件存在于您正在运行的服务器上
  • 该文件位于子模板的目录中(尽管如果它位于 twentyeleven 目录中,它应该可以工作)
  • twentyeleven 目录中没有同名的文件,(我认为)优先
  • 文件名以.php
  • 结尾
  • 模板"和名称:"之间只有一个空格(使用的正则表达式包含文字模板名称:)
  • the file exists on the server you're running on
  • the file's in the child template's directory (though it should work if it's in the twentyeleven directory)
  • there's no file with the same name in the twentyeleven directory, which (I think) would take precedence
  • the file name ends in .php
  • you only have a single space between "Template" and "Name:" (the regex used contains the literal Template Name:)

否则,下拉列表由 wp-admin/includes/theme.php 中的 get_page_templates 函数填充.可能值得在其中粘贴一些调试代码,以查看 $templates 变量是否包含 coming-soon.php.

Failing that, the dropdown is populated by the get_page_templates function in wp-admin/includes/theme.php. Might be worth sticking some debug code in there to see if the $templates variable includes coming-soon.php.