在 WordPress 中创建自定义页面模板 [英] Creating a custom page template in WordPress

查看:36
本文介绍了在 WordPress 中创建自定义页面模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用二十四主题并创建了一个带有自己的 style.css 的子主题.现在我想创建一个自定义页面模板.从我读过的过程来看,似乎是:

  1. 复制现有的页面模板,例如 page.php,并将其放在父主题目录中,但为其指定一个新名称.
  2. 对该新模板进行所需的更改.
  3. 您创建的任何元素都可以被赋予唯一的类,然后通过子主题中的 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:

  1. 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.
  2. Make the changes you want to this new template.
  3. 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

  1. page-{slug}.php
  2. page-{id}.php
  3. page.php
  4. index.php

这篇关于在 WordPress 中创建自定义页面模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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