admin管理员组

文章数量:1391960

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.

本文标签: theme developmentTemplate Hierarchy for custom post type pages