Can I override a CPT template on a per post basis with Gutenberg block editor?

I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).I am wondering

I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).

I am wondering if it is possible to override a post within the Event CPT with the Gutenberg block editor, instead of using the php template every-time, is this possible?

I would ideally like the template file to apply to all my CPT posts, except one or two of them, which will require much different display.

EDIT: I guess in a more generic sense I am looking for optional template functionality for a CPT. Ability to use the provided template, or ignore it and utilize the block editor with Gutenberg.

I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).

I am wondering if it is possible to override a post within the Event CPT with the Gutenberg block editor, instead of using the php template every-time, is this possible?

I would ideally like the template file to apply to all my CPT posts, except one or two of them, which will require much different display.

EDIT: I guess in a more generic sense I am looking for optional template functionality for a CPT. Ability to use the provided template, or ignore it and utilize the block editor with Gutenberg.

Share Improve this question edited Jun 3, 2019 at 22:21 PressWord asked Jun 3, 2019 at 21:55 PressWordPressWord 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Since 4.7 Custom Post Types have supported custom templates, just like Pages. So you could copy your theme's generic page template to a new template file, and add this to the top.

<?php
/*
Template Name: Block editor template
Template Post Type: my-post-type
*/

That will let you switch the template for your my-post-type post to a template that looks and works just like a normal page.

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

相关推荐

  • Can I override a CPT template on a per post basis with Gutenberg block editor?

    I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).I am wondering

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信