应该在哪里放置WordPress自定义页面模板?

时间:2017-09-29 11:54:21

标签: php wordpress

我只是询问自定义页面模板:

如果我把它放在子文件夹中它会起作用,或者它应该放在根目录中。

例如,我创建了一个名为custom-page-awesome.php的模板,并将其放在 nytemplate 目录中。

请让我知道,当我编辑某个页面或需要使用自定义代码时,会自动检测到它。

3 个答案:

答案 0 :(得分:0)

我相信WordPress无法识别不在主题根目录中的模板文件。这是除非您使用以下函数get_template_part( 'your-template-file' );

更多相关内容:https://developer.wordpress.org/reference/functions/get_template_part/

答案 1 :(得分:0)

您需要将此注释行放在主题文件夹根目录中的模板php文件之上。它将在wordpress后台的页面下拉菜单中显示模板:

答案 2 :(得分:0)

WordPress识别子文件夹' / page-templates /'。因此,最好将全局页面模板存储在此文件夹中,以帮助他们保持井井有条:https://developer.wordpress.org/themes/template-files-section/page-template-files/