如何让 WordPress 识别我新创建的页面模板?
我最近创建了一个新的模板页面,我将必需的内容
<?php
/*
Template Name: New Page Template for testing
*/
?>
作为代码的第一部分。
然后我将其上传到 /www/wp-content/themes/neoclassical (所有其他自定义页面模板都位于其中)。
我现在尝试将任何页面的模板更改为新主题,但新的页面模板不显示!
关于我需要做什么才能使其显示为“添加页面”区域上的选项的任何想法?
我尝试过将主题更改为另一种主题并返回到原始主题,但均无济于事。
谢谢大家。
I recently created a new template page, I put the obligatory
<?php
/*
Template Name: New Page Template for testing
*/
?>
as the first part of the code.
Then I uploaded it to the /www/wp-content/themes/neoclassical (where all of the other custom page templates are located).
I now try to change the Template of any page to the new theme, and the new page template does not show!
Any ideas on what I need to do to get this to show up as an option on the "Add Page" area?
I have tried changing the theme to another one and back to the original theme, all to no avail.
Thanks everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于未来的访问者:
我刚刚在 WordPress 4.8 中遇到了这个问题。事实证明,我已从主题中删除了
index.php
文件,这导致主题不显示模板下拉列表。要解决此问题,只需在主题文件夹中创建一个空的
index.php
文件即可。(WordPress 确实会尝试警告您管理面板中的主题页面上缺少此文件 - 但您在尝试修复此错误时可能不会访问该页面。)
更新: Trace 在下面的评论中提到,缺少
style.css
也可能导致这种情况发生。For future visitors:
I just had this problem in WordPress 4.8. Turns out I had removed the
index.php
file from my theme, which was causing the theme not to show the template dropdown.To fix this just create an empty
index.php
file in your theme folder.(WordPress does try to warn you this file is missing on the Themes page in the admin panel — but you might not visit that page while trying to fix this bug.)
Update: Trace has mentioned in the comment below that a missing
style.css
can also cause this to happen.如果自定义模板的代码不好。它不会显示。
尝试使用此处的示例之一。
http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
if the code of the custom template is not good. it wont show.
try using one of the examples here.
http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
因此,原来的开发人员已将网站的备份副本放在“LiveFiles”目录中,并将该网站指向“Stuff”。我刚刚上传到错误的区域。
So, it turns out that the original developer had put the backup copy of the site in the "LiveFiles" directory, and had pointed the site to "Stuff". I was just uploading to the wrong area.
您只需写下这句话,然后转到管理面板并添加新页面,然后您会看到模板框并找到您的模板页面名称。
you just write this sentence and go to admin panal and add new page than you see Template box and find your template page name.
如果在工作主题中突然发生这种情况,请尝试从 wp_options 表中删除以 _transient_files 开头的行。这为我解决了这个问题。
In case this suddenly happens in a working theme, try to delete delete the row starting with _transient_files from wp_options table. That solved the issue for me.