page-{slug}.php vs. template-{slug}.php

I am working on a legacy WordPress application, and I came across a few files with the naming template-{slug}.php, which

I am working on a legacy WordPress application, and I came across a few files with the naming template-{slug}.php, which were placed in the child-theme folder. I'm surprised I came up with no support via Google when I looked into this. I see lots of support about page-{slug}.php files, but that seems to be a simpler concept which I understand easily.

It's clear to me that the template-{slug}.php files control the layout of pages that are set to use the corresponding template, which I can select in the Edit Page area. But on other WordPress applications that I'm working on, I don't see any choice for a template for pages when I edit them.

So my question is, should I assume that this is a theme-based functionality, where some themes provide support for files with the template-{slug}.php naming? I'm using Sparkling Theme.

Or do all WordPress applications allow for such files? If so, where can I find instructions on how to use template-{slug}.php files? Or is there another way these days to create a true "template" where multiple pages can use its layout?

I am working on a legacy WordPress application, and I came across a few files with the naming template-{slug}.php, which were placed in the child-theme folder. I'm surprised I came up with no support via Google when I looked into this. I see lots of support about page-{slug}.php files, but that seems to be a simpler concept which I understand easily.

It's clear to me that the template-{slug}.php files control the layout of pages that are set to use the corresponding template, which I can select in the Edit Page area. But on other WordPress applications that I'm working on, I don't see any choice for a template for pages when I edit them.

So my question is, should I assume that this is a theme-based functionality, where some themes provide support for files with the template-{slug}.php naming? I'm using Sparkling Theme.

Or do all WordPress applications allow for such files? If so, where can I find instructions on how to use template-{slug}.php files? Or is there another way these days to create a true "template" where multiple pages can use its layout?

Share Improve this question asked Oct 16, 2019 at 15:44 MarkMark 3211 gold badge3 silver badges16 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 5

So my question is, should I assume that this is a theme-based functionality, where some themes provide support for files with the template-{slug}.php naming?

Correct.

Or do all WordPress applications allow for such files? If so, where can I find instructions on how to use template-{slug}.php files? Or is there another way these days to create a true "template" where multiple pages can use its layout?

I don't really understand what you mean by "all WordPress applications". In WordPress, templates are provided by the theme. So if you want a custom template that can be used for pages, it needs to be part of the theme. The documentation for how page templates work, including how custom selectable templates work, is here.

If you're using a child theme, you'd just create the template you want, probably basing it off an existing template, and include it in the child theme. One thing that you'll notice from the documentation, that I've linked above, is that page-{slug}.php has a specific meaning that allows the template to be used automatically. template-{slug}.php does not have any such meaning. It's merely a convention. What makes a template selectable is the presence of the Template Name comment at the beginning of the file:

<?php
/**
 * Template Name: Full Width Page
 */

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745075436a4609807.html

相关推荐

  • page-{slug}.php vs. template-{slug}.php

    I am working on a legacy WordPress application, and I came across a few files with the naming template-{slug}.php, which

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信