在 WordPress 中创建自定义页面模板 [英] Creating a custom page template in WordPress
问题描述
我正在使用二十四主题并创建了一个带有自己的 style.css 的子主题.现在我想创建一个自定义页面模板.从我读过的过程来看,似乎是:
- 复制现有的页面模板,例如 page.php,并将其放在父主题目录中,但为其指定一个新名称.
- 对该新模板进行所需的更改.
- 您创建的任何元素都可以被赋予唯一的类,然后通过子主题中的 style.css 设置样式.
这听起来对吗?
一个问题是,新的模板是如何分配给页面的?我是否必须手动进入页面属性并选择新模板,还是会自动从模板层次结构中拉出?
感谢您的帮助.
您必须在 Page Attributes
部分中进行选择.请参考以下网址.
I'm using the twentyfourteen theme and have created a child theme with its own style.css. Now I'd like to create a custom page template. From all I've read the process seems to be:
- Make a copy of the existing page template, e.g., page.php, and place it still in the parent theme directory but give it a new name.
- Make the changes you want to this new template.
- Any elements you create can be given unique classes and then styled by the style.css in the child theme.
Does that sound right?
One question is, How is the new template assigned to the page? Do I have to manually go into the Page Attributes and select the new template, or will it get pulled automatically from the template hierarchy?
Thanks for your help.
You have to choose in the Page Attributes
section. Refer the below URL.
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
http://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/
Custom page template
- page-{slug}.php
- page-{id}.php
- page.php
- index.php
这篇关于在 WordPress 中创建自定义页面模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!