无法将自定义页面模板添加到我的子主题 [英] Cannot add custom page template to my child theme

查看:28
本文介绍了无法将自定义页面模板添加到我的子主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Wordpress 3.3.1.

I'm running Wordpress 3.3.1.

我正在编写一个修改默认 211 主题的子主题.一切看起来都很正常,除了当我添加自定义页面模板时,它没有出现在添加/编辑屏幕中(所以我无法使用它!).

I'm writing a child theme that modifies the default twentyeleven theme. Everything seems normal, except that when I add a custom page template, it doesn't appear in the add/edit screen (so I can't use it!).

要详细说明正常",以下是工作原理:我的子主题出现并正常激活.我的 CSS 代码(在 style.css 中)出现了.我的模板层次结构中的文件正在运行(例如:front-page.php、page.php)

To elaborate on "normal", here's what IS working: My child theme appears and activates normally. My CSS code (in style.css) is appearing. My files from the template hierarchy are working (ex: front-page.php, page.php)

我已经阅读并重新阅读了代码,我的自定义页面模板文件(coming-soon.php")似乎有正确的标题:

I've read and reread the codex, and my custom page template file ("coming-soon.php") seems to have the correct header:

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

那么为什么它不会显示在模板"下拉列表中???

So why won't it show up under the "Template" drop-down???

我已添加自定义模板数十次,但从未遇到过此问题.我能想到的唯一可能的区别是我正在编写一个儿童主题(即使代码说明这应该无关紧要),或者可能是 WP 的最新更新有所不同.

I've added custom templates dozens of times and never had this problem. The only possible difference I can think of is that I'm writing a child theme (even though the codex says this shouldn't matter), or perhaps it's a difference in the newest update of WP.

推荐答案

我无法通过全新安装的 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:     stackoverflow-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.

这篇关于无法将自定义页面模板添加到我的子主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆