最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Template Hierarchy for custom post type pages

programmeradmin1浏览0评论

So I have a custom post type that is called recipe and then I have a page called /recipes/ - What would be the proper way to hook a template for my recipes page?

I have the file single-recipe.php following the WordPress hierarchy with this inside:

<?php

/*
Template Name: Recipe
Template Post Type: post, page
*/

echo 'Hello';

But I'm not getting any templating output:

The below is my folder structure:

So I have a custom post type that is called recipe and then I have a page called /recipes/ - What would be the proper way to hook a template for my recipes page?

I have the file single-recipe.php following the WordPress hierarchy with this inside:

<?php

/*
Template Name: Recipe
Template Post Type: post, page
*/

echo 'Hello';

But I'm not getting any templating output:

The below is my folder structure:

Share Improve this question asked Feb 11, 2020 at 21:39 DevSemDevSem 2092 silver badges11 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

The filename single-recipe.php is telling WordPress "only use this file to display single 'recipe' CPT posts."

If you want to use it as a Page template, you can either rename the file tpl-recipe.php (or something similar, it doesn't have to be this filename, it just has to not be a recognized pattern like single-cptslug.php) - in which case you'll have to manually choose that template every time you create a new Recipe -

Or, you can have two files. One named single-recipe.php which does NOT have the comments at the top, and one named tpl-recipe.php (or similar) which DOES have the comments at the top.

发布评论

评论列表(0)

  1. 暂无评论